# Bad value  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-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/)

The `href` of an `<a>` element has a literal space in its URL path, and the URL is too long for the validator to quote in the message.

A valid URL has no literal spaces. In the path (the part after the domain and before any `?` or `#`), a space has to be percent-encoded as `%20`. Browsers encode the space themselves when someone follows the link, so the link often works, but the `href` is still not a valid URL.

The validator usually prints the bad value between `Bad value` and `for attribute`. When the value is 200 characters or longer, it leaves the value out, which is why this message has nothing between them. Values that long tend to come from file names written as whole sentences, or from a block of text pasted into a link field by mistake. To find the link, check the source line shown with the issue, or search the page source for `href` values that contain spaces.

The fix is the same as for a short URL: replace each space with `%20`. If you control the file, a short name with hyphens instead of spaces, such as `annual-report.pdf`, is easier to link to. If the `href` holds text that was never meant to be a URL, put the right address back in the link.

## Invalid example

```html
<a href="/downloads/reports/Annual report on community health programs and volunteer outreach in the northern region with survey results, budget breakdown and recommendations for the next two financial years.pdf">
  Download the annual report
</a>
```

## Valid example

```html
<a href="/downloads/reports/Annual%20report%20on%20community%20health%20programs%20and%20volunteer%20outreach%20in%20the%20northern%20region%20with%20survey%20results,%20budget%20breakdown%20and%20recommendations%20for%20the%20next%20two%20financial%20years.pdf">
  Download the annual report
</a>
```
