Skip to main content
HTML Validation

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

About This HTML Issue

Hash (#) characters can be used in an href attribute to link to a specific part of a document.

For example, if we have this page with several sections, each of them marked with an ID:

<h1>Frequently Asked Questions</h1>

<h2 id="pricing">Pricing</h2>
<p>All about pricing...</p>

<h2 id="terms">Terms</h2>
<p>You can find our terms at...</p>

<h2 id="guarantee">Guarantee</h2>
<p>We offer a guarantee...</p>

You can link to a specific part of that document, for example if this page URL is /faqs and you want to link to the Guarantee section you could use:

<a href="/faqs#guarantee">Guarantee</a>

Or, if you’re linking from inside the same document, for example in a table of contents, you could just use:

<a href="#guarantee">Guarantee</a>

As there can only be one fragment in an URL, the # character should only be used once. The following would be an invalid href:

<a href="/faqs#guarantee#pricing">Bad</a>

If needed, the # could be encoded as %23.

Last reviewed: March 15, 2023

Was this guide helpful?

Find issues like this automatically

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

Ready to validate your sites?
Start your free trial today.