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

A # character inside the fragment portion of a URL is not valid and must be percent-encoded as %23.

The fragment identifier in a URL is everything after the first # character. Because # itself is the delimiter that starts the fragment, any additional # characters within the fragment are illegal according to RFC 3986. Browsers may handle these gracefully, but the markup is technically invalid.

This commonly happens when an id value on the target element contains a #, or when a URL is copied from somewhere and pasted without encoding. The fix is to replace any extra # inside the href fragment with %23. Better yet, avoid using # in id values altogether.

Invalid example

<a href="#section#2">Go to section</a>

The fragment section#2 contains a second #, which is not allowed.

Fixed example

Option 1: percent-encode the # inside the fragment.

<a href="#section%232">Go to section</a>

Option 2 (preferred): change the target id so it does not contain # at all.

<h2 id="section-2">Section 2</h2>
<a href="#section-2">Go to section</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
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries