# Bad value X for attribute “href” on element “a”: Illegal character in path segment. Space is not allowed.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-href-on-element-a-illegal-character-in-path-segment-space-is-not-allowed
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

Spaces in the `href` attribute of an `<a>` element are not valid URL characters and must be encoded as `%20`.

URLs follow the syntax defined in [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986), which does not allow literal space characters in any component of a URI. When a browser encounters a space in an `href` value, it often silently corrects it, but the HTML is still technically invalid. The W3C validator flags this because the raw space violates the URL specification.

To fix the issue, replace each space in the URL with `%20`. This is the percent-encoded form of the space character. If the URL points to a local file or path that genuinely contains spaces, the encoding is still required.

Some common situations where this appears:

- Links to files with spaces in their names, like `my document.pdf`.
- Paths that include folder names with spaces, like `/my folder/page.html`.
- Query parameters that contain unencoded spaces.

## HTML examples

### Invalid: space in href

```html
<a href="/my folder/my document.pdf">Download</a>
```

### Valid: spaces encoded as %20

```html
<a href="/my%20folder/my%20document.pdf">Download</a>
```

If you control the file or directory names, renaming them to avoid spaces altogether is a simpler long term fix. Use hyphens or underscores instead:

```html
<a href="/my-folder/my-document.pdf">Download</a>
```
