Skip to main content
HTML Validation

Bad value for attribute “src” on element “img”: Illegal character in fragment: space is not allowed.

About This HTML Issue

A space character in the fragment portion of a URL (the part after #) is not allowed in the src attribute of an img element.

URLs follow the syntax defined in RFC 3986, which does not permit literal spaces anywhere in the URI, including the fragment identifier. Browsers may silently handle spaces by percent-encoding them, but the raw HTML remains invalid. The W3C validator flags this because the src value must be a valid URL before the browser ever processes it.

To fix the issue, replace each space in the URL with %20, which is the percent-encoded form of a space character. This applies to all parts of the URL: the path, query string, and fragment.

A common cause is copying a URL from a browser address bar or a document system where filenames or anchors contain spaces. Another cause is linking to a named anchor (id) on a page where the id value itself contains a space, which is also invalid HTML — id values must not contain spaces.

HTML examples

Invalid: space in fragment

<img src="diagram.svg#my section" alt="Diagram of section layout">

Valid: percent-encoded space

<img src="diagram.svg#my%20section" alt="Diagram of section layout">

If you control the target resource, a better fix is to remove the space from the fragment identifier entirely:

<img src="diagram.svg#my-section" alt="Diagram of section layout">

Using hyphens or underscores instead of spaces in fragment identifiers and file names avoids this class of problem altogether.

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