Skip to main content
HTML Validation

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

About This HTML Issue

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

<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

<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>

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
€5 / week

1K Weekly

1,000 monthly checks. Cancel anytime.

Get 1K Weekly →

Join teams across 40+ countries