HTML Guides
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
The href value on the <a> element contains a literal > character, which is not allowed in a URL path.
The URL standard does not allow a raw > anywhere in a URL. Writing it as > doesn't change that, because the HTML parser decodes > back to > before the URL is read. Browsers still follow the link, but they percent-encode the character themselves and request a path that usually does not exist.
When the value starts with >, it is often not an address at all. Some sites put a > in front of link text as a small arrow, as in > Read the full report. If an editor pastes that text into the URL field of a CMS instead of the label field, the whole sentence becomes the href, and the browser treats it as a relative path to a missing page. A stray > at the end of a value, like href="/reports/annual>", is usually a typo in the markup.
Put the real address in href and keep the text inside the element. The validator reports only the first illegal character in a value, so if you remove the > but leave the sentence in href, it will report the spaces next. If a path really needs a >, write it as %3E.
Invalid example
<a href="> Read the full report">Read the full report</a>
Valid example
<a href="/reports/annual">Read the full report</a>
The href value on the <a> element contains a literal < character, which is not allowed in a URL path.
The URL standard does not allow a raw < anywhere in a URL. Escaping it as < does not help, because the HTML parser turns < back into < before the URL is read. If a path really needs the character, write it as %3C.
A value that starts with part of a tag, such as <div class=, means a template or content filter wrote HTML where a URL belongs. Lazy-loading and video embed plugins can do this when they swap a video URL for placeholder markup without checking whether the URL sits inside an attribute. The first " in that markup closes the href, so the value stops at class= and the browser treats it as a relative path to a page that doesn't exist.
The rest of the injected tag spills into the <a> start tag as broken attributes. That's why the validator usually also reports a stray end tag and a quote in an attribute name for the same link. Those errors go away once the href holds a plain URL.
Other values with a < come from angle brackets copied along with an address, as in <https://www.example.com/> from a plain-text email, or from placeholders like /files/<name>.pdf left in a template. Remove the brackets or fill in the real value.
Invalid example
<a href="<div class="video-embed" data-src="https://www.example.com/embed/abc123"></div>">Watch the video</a>
Valid example
<a href="https://www.example.com/embed/abc123">Watch the video</a>
The href value on the <a> element contains  (U+FFFC, the object replacement character), which isn't allowed in a URL path.
Rich-text editors and other text systems use U+FFFC as a placeholder for an inline image or other embedded object. Copying text out of one of them, or editing a link next to an inline image, can leave the placeholder inside the URL. Depending on the font, it's invisible or shows up as a small box, so the address can look right in the editor.
It never belongs in an address. Browsers send it as %EF%BF%BC, so /jobs/apply/ is requested as /jobs/apply%EF%BF%BC/, which most likely doesn't exist. Percent-encoding it yourself silences the validator but the link stays broken, so delete the character instead. Retyping the URL in the link field, or editing the link in the editor's HTML view, gets rid of it. To find every occurrence in a template or an export, run a regular-expression search for \uFFFC or \x{FFFC}, depending on the tool.
The same character in a query string or a fragment gets a similar message that names the query or the fragment instead of a path segment.
Invalid example
<a href="/jobs/apply/">Apply now</a>
Valid example
<a href="/jobs/apply/">Apply now</a>
The href value on the <a> element contains a literal | (pipe) character, which is not allowed in a URL path.
The URL standard doesn't list | among the characters a URL can contain, so a pipe in the path has to be written as %7C. Browsers still follow the link, but the markup is invalid.
This usually comes from a CMS or template that builds the path from a page title. A title like "Summer concert | Tickets" uses the pipe as a separator. If the slug function only lowercases the text and turns spaces into hyphens, the | stays and the path ends up as summer-concert-|-tickets. Fix the slug function so it drops anything other than letters, digits and hyphens. The new slug gives the page a new address, so redirect the old URL to it. If the URLs can't change, write the pipe as %7C in the href instead.
When the href is very long, the validator leaves the value out of the message. The cause and the fix are the same.
Invalid example
<a href="/events/42/summer-concert-|-tickets">Summer concert | Tickets</a>
Valid example
Remove the pipe from the slug:
<a href="/events/42/summer-concert-tickets">Summer concert | Tickets</a>
If the URL has to stay the same, percent-encode the pipe:
<a href="/events/42/summer-concert-%7C-tickets">Summer concert | Tickets</a>
The href value on the <a> element contains a literal " character, which is not allowed in a URL path.
The quotes around an attribute value are HTML syntax, not part of the URL. A " inside the value is different: written as ", or typed inside a single-quoted attribute such as href='"/brochure.pdf"', it becomes a character of the URL itself. The URL standard does not allow a raw " in a path, so the validator rejects the whole value. Browsers still follow the link, but they send the quote as %22 and request a path that usually does not exist.
The stray quote rarely comes from someone typing it. More often the code that writes the link adds it. A template that JSON-encodes the URL before printing it, for example with JSON.stringify(url), wraps the address in an extra pair of quotes. A CMS that stores link settings as JSON, like {"url":"/brochure.pdf","target":"_blank"}, can print the wrong piece of that string, so href ends up holding a fragment such as "url":"/brochure.pdf" or the tail of the object instead of the address. Fix the template so it outputs the plain URL. If a file name really contains a double quote, write it as %22 in the path.
Invalid example
<a href=""/brochure.pdf"">Download the brochure</a>
Valid example
<a href="/brochure.pdf">Download the brochure</a>
The href value on the <a> element contains � (U+FFFD, the Unicode replacement character), which the validator doesn't allow in a URL path.
A text decoder puts � in place of bytes that don't make a valid character in the encoding it's reading. In a URL, it marks where the original character, often a letter with an accent such as é, got lost. Browsers send it as %EF%BF%BD, so the link most likely leads to a page that doesn't exist.
Most of the time the page's encoding is to blame. With no <meta charset> in the document and no charset from the server, the validator falls back to windows-1252 and reads UTF-8 bytes as the wrong characters. The reverse mismatch is a page that declares utf-8 while the file is saved as windows-1252, where a byte such as 0xE9 (é) isn't valid UTF-8.
Either way, each byte that can't be decoded becomes �, and the report also shows "Malformed byte sequence" or "Unmappable byte sequence" errors. Leftover letters like à or  next to the � in the reported value point the same way. Save the file as UTF-8 and declare it with <meta charset="utf-8"> at the top of <head>, which also fixes any other garbled text on the page.
When the encoding is already right and the error doesn't go away, the � is in the source itself. The character was lost earlier, for example during an import into a CMS, and saved as �, so no encoding setting can bring it back. Write the intended character, percent-encode it (é is %C3%A9), or use an ASCII-only slug.
Invalid example
<a href="/menu/caf�-specials.html">Café specials</a>
Valid example
Save the file as UTF-8, declare the encoding and write the intended character:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Menu</title>
</head>
<body>
<a href="/menu/café-specials.html">Café specials</a>
</body>
</html>
To keep the URL ASCII-only, percent-encode the character instead:
<a href="/menu/caf%C3%A9-specials.html">Café specials</a>
Spaces in the href attribute of an <a> element are not valid URL characters and must be encoded as %20.
URLs follow the syntax defined in RFC 3986, which does not allow literal space characters in any component of a URI. When a browser encounters a space in an href value, it often silently corrects it, but the HTML is still technically invalid. The W3C validator flags this because the raw space violates the URL specification.
To fix the issue, replace each space in the URL with %20. This is the percent-encoded form of the space character. If the URL points to a local file or path that genuinely contains spaces, the encoding is still required.
Some common situations where this appears:
- Links to files with spaces in their names, like
my document.pdf. - Paths that include folder names with spaces, like
/my folder/page.html. - Query parameters that contain unencoded spaces.
HTML examples
Invalid: space in href
<a href="/my folder/my document.pdf">Download</a>
Valid: spaces encoded as %20
<a href="/my%20folder/my%20document.pdf">Download</a>
If you control the file or directory names, renaming them to avoid spaces altogether is a simpler long term fix. Use hyphens or underscores instead:
<a href="/my-folder/my-document.pdf">Download</a>
Square brackets ([ and ]) are not valid characters in a URL path and must be percent-encoded.
The HTML specification requires that the href attribute on an <a> element contains a valid URL. According to RFC 3986, square brackets are reserved characters that are only permitted in the host component of a URI (specifically for IPv6 addresses like [::1]). When they appear in the path, query, or fragment components, they must be percent-encoded as %5B for [ and %5D for ].
This commonly happens with URLs that contain array-like query parameters (e.g., filter[status]=active) or paths that include brackets for some framework-specific routing convention.
To fix the issue, replace every [ with %5B and every ] with %5D in the URL path or query string.
HTML examples
Invalid: square brackets in the URL
<a href="/products?filter[color]=red&filter[size]=large">
Red, large products
</a>
Valid: percent-encoded square brackets
<a href="/products?filter%5Bcolor%5D=red&filter%5Bsize%5D=large">
Red, large products
</a>
The encoded version is functionally equivalent. Most web servers and frameworks will decode %5B and %5D back to [ and ] automatically when processing the request.
The URL in this link has a space in its port number, and a port can only contain digits.
In a URL such as https://example.com:8080/, the part after the colon that follows the host is the port. The URL Standard allows only digits there, up to the next /, ? or #. When the parser meets a space before that point, it gives up on the whole URL. A browser can't follow a link it can't parse, so clicking it does nothing.
The usual cause is a phone link written as http://tel: followed by a number with spaces between the digit groups, like http://tel:555 123 4567. The parser reads tel as a host name and the phone number as its port, then fails at the first space. Removing the spaces doesn't help. The link would point at a web server called tel, and most phone numbers are larger than 65535, the highest port allowed.
Phone links use the tel: scheme on its own, with no http:// in front, as defined in RFC 3966. A tel: URL can't contain spaces either, so write the digits together, starting with + and the country code. To keep the number easy to read, put the spaced version in the link text.
When the URL really has a port, the space is usually a typo or whitespace left by a template, as in https://example.com:8080 /reports. Delete it.
Invalid example
<p>Call us at <a href="http://tel:555 123 4567">555 123 4567</a>.</p>
<a href="https://example.com:8080 /reports">Open the reports</a>
Valid example
<p>Call us at <a href="tel:+15551234567">+1 555 123 4567</a>.</p>
<a href="https://example.com:8080/reports">Open the reports</a>
Square brackets ([ and ]) are not valid characters in URLs according to RFC 3986 and must be percent-encoded in the href attribute of <a> elements.
URLs have a strict set of allowed characters. Square brackets are reserved exclusively for IPv6 addresses in the host portion of a URL (e.g., http://[::1]/). Anywhere else in a URL, including query strings, they must be percent-encoded: [ becomes %5B and ] becomes %5D.
This issue commonly appears when linking to URLs that use square brackets in query parameters, a pattern found in some PHP frameworks and APIs (e.g., ?filter[name]=value). While most browsers handle unencoded brackets without problems, the HTML specification requires valid URLs, and the W3C validator flags the violation.
Invalid example
<a href="https://example.com/results?filter[status]=active&filter[role]=admin">
View results
</a>
Valid example
Replace [ with %5B and ] with %5D:
<a href="https://example.com/results?filter%5Bstatus%5D=active&filter%5Brole%5D=admin">
View results
</a>
The browser will decode the percent-encoded characters when sending the request, so the server receives the same query string either way.
The | (pipe) character is not allowed in URLs and must be percent-encoded as %7C in the href attribute of an <a> element.
URLs follow the syntax rules defined in RFC 3986. The pipe character is not among the allowed characters in the query component of a URI. When a URL contains a literal |, browsers will often handle it gracefully, but the HTML is technically invalid. The fix is to replace every | with its percent-encoded equivalent %7C.
This commonly appears when linking to external APIs, legacy systems, or content management platforms that use | as a delimiter in query strings.
HTML examples
Invalid example
<a href="https://example.com/search?filters=color|size|price">Search</a>
Valid example
<a href="https://example.com/search?filters=color%7Csize%7Cprice">Search</a>
If the URLs are generated dynamically in JavaScript, encodeURI() or encodeURIComponent() will handle the encoding automatically:
const filters = "color|size|price";
const url = `https://example.com/search?filters=${encodeURIComponent(filters)}`;
// Result: https://example.com/search?filters=color%7Csize%7Cprice
URLs follow strict syntax rules defined by RFC 3986, which does not permit literal space characters anywhere in a URI. When the W3C validator encounters a space in the href attribute of an <a> element — particularly within the query string (the part after the ?) — it flags it as an illegal character.
While most modern browsers will silently fix malformed URLs by encoding spaces for you, relying on this behavior is problematic for several reasons:
- Standards compliance: The HTML specification requires that
hrefvalues contain valid URLs. A space makes the URL syntactically invalid. - Interoperability: Not all user agents, crawlers, or HTTP clients handle malformed URLs the same way. Some may truncate the URL at the first space or reject it entirely.
- Accessibility: Screen readers and assistive technologies may struggle to interpret or announce links with invalid URLs.
- Link sharing and copy-pasting: If a user copies the link from the source or if the URL is used in an API or redirect, the unencoded space can cause breakage.
To fix this issue, replace every literal space character in the URL with %20. Within query string values, you can also use + as a space encoding (this is the application/x-www-form-urlencoded format commonly used in form submissions). If you're generating URLs dynamically, use your programming language's URL encoding function (e.g., encodeURIComponent() in JavaScript, urlencode() in PHP, or urllib.parse.quote() in Python).
Examples
Incorrect — spaces in the query string
<a href="https://example.com/search?query=hello world&lang=en">Search</a>
The space between hello and world is an illegal character in the URL.
Correct — space encoded as %20
<a href="https://example.com/search?query=hello%20world&lang=en">Search</a>
Correct — space encoded as + in query string
<a href="https://example.com/search?query=hello+world&lang=en">Search</a>
Using + to represent a space is valid within query strings and is commonly seen in URLs generated by HTML forms.
Incorrect — spaces in the path and query
<a href="https://example.com/my folder/page?name=John Doe">Profile</a>
Correct — all spaces properly encoded
<a href="https://example.com/my%20folder/page?name=John%20Doe">Profile</a>
Generating safe URLs in JavaScript
If you're building URLs dynamically, use encodeURIComponent() for individual parameter values:
<script>
const query = "hello world";
const url = "https://example.com/search?query=" + encodeURIComponent(query);
// Result: "https://example.com/search?query=hello%20world"
</script>
Note that encodeURIComponent() encodes spaces as %20, which is safe for use in any part of a URL. Avoid using encodeURI() for query values, as it does not encode certain characters like & and = that may conflict with query string syntax.
A URL in an href attribute contains a character that must be percent-encoded before it can appear in a query string.
URLs follow the syntax rules defined in RFC 3986. The query component of a URL (everything after the ?) allows a specific set of characters: unreserved characters (A-Z, a-z, 0-9, -, ., _, ~), sub-delimiters (!, $, &, ', (, ), *, +, ,, ;, =), plus :, @, /, and ?. Characters outside this set, such as {, }, |, ^, [, ], spaces, and non-ASCII characters like é or ñ, are illegal in their raw form and must be percent-encoded.
Percent-encoding replaces each disallowed byte with a % followed by its two-digit hexadecimal value. For example, a space becomes %20, a pipe | becomes %7C, and { becomes %7B.
Common causes of this error include:
- Pasting a URL directly from a browser address bar or CMS that displays decoded characters.
- Using curly braces for template placeholders in URLs without encoding them.
- Including spaces or non-ASCII characters in query parameter values.
HTML examples
Invalid: raw illegal characters in the query string
<a href="https://example.com/search?q=hello world&cat=sci|tech">Search</a>
The space between hello and world and the pipe | between sci and tech are not allowed in a URL query.
Valid: percent-encoded characters
<a href="https://example.com/search?q=hello%20world&cat=sci%7Ctech">Search</a>
Each illegal character is replaced with its percent-encoded equivalent: space is %20 and | is %7C.
The URL standard defines a specific set of characters that are allowed to appear literally in a URL's query string. Characters outside this allowed set — such as |, [, ], {, }, ^, and unencoded spaces — must be percent-encoded. Percent-encoding replaces the character with a % sign followed by its two-digit hexadecimal ASCII code.
This matters for several reasons. Browsers may handle illegal characters inconsistently — some might silently fix them while others may not, leading to broken links. Screen readers and assistive technologies rely on well-formed URLs to properly announce link destinations. Search engine crawlers may also fail to follow URLs with illegal characters, which can hurt discoverability. Using properly encoded URLs ensures your links work reliably across all user agents and conform to both the HTML and URL specifications.
Common Characters That Need Encoding
Here are frequently encountered characters that trigger this validation error:
| Character | Percent-Encoded |
|---|---|
| (space) | %20 (or + in query strings) |
| | %7C |
[ | %5B |
] | %5D |
{ | %7B |
} | %7D |
^ | %5E |
Note that characters like ?, =, &, and # have special meaning in URLs and are allowed in their respective positions. For example, ? starts the query string, & separates parameters, and = separates keys from values. However, if these characters appear as part of a parameter's value (rather than as delimiters), they must also be percent-encoded.
How to Fix It
- Identify the illegal character mentioned in the validator's error message.
- Replace it with its percent-encoded equivalent.
- If you're generating URLs dynamically with a server-side language, use built-in encoding functions like
encodeURIComponent()in JavaScript,urlencode()in PHP, orurllib.parse.quote()in Python.
Examples
❌ Incorrect: Unencoded pipe character in query string
<a href="https://example.com/search?filter=red|blue">Search</a>
✅ Correct: Pipe character percent-encoded as %7C
<a href="https://example.com/search?filter=red%7Cblue">Search</a>
❌ Incorrect: Unencoded square brackets in query string
<a href="https://example.com/api?items[0]=apple&items[1]=banana">View items</a>
✅ Correct: Square brackets percent-encoded
<a href="https://example.com/api?items%5B0%5D=apple&items%5B1%5D=banana">View items</a>
❌ Incorrect: Unencoded space in query string
<a href="https://example.com/search?q=hello world">Search</a>
✅ Correct: Space encoded as %20
<a href="https://example.com/search?q=hello%20world">Search</a>
If you're building URLs in JavaScript, use encodeURIComponent() on individual parameter values rather than encoding the entire URL. This function handles all characters that need encoding while leaving the URL structure intact:
const query = "red|blue";
const url = `https://example.com/search?filter=${encodeURIComponent(query)}`;
// Result: "https://example.com/search?filter=red%7Cblue"
Avoid using encodeURI() for this purpose, as it does not encode characters like [, ], or | that are illegal in query strings. Always use encodeURIComponent() for encoding individual query parameter names and values.
A < character in an href attribute value is not allowed because it is a reserved character in URLs and must be percent-encoded.
The href attribute on an <a> element must contain a valid URL or URL fragment. Characters like <, >, {, }, and others are not permitted directly in URLs according to RFC 3986. The < character is especially problematic because browsers and parsers interpret it as the start of an HTML tag, which can break your markup and introduce security risks like XSS vulnerabilities.
This error commonly appears when template syntax (e.g., {{variable}}), unescaped user input, or malformed URLs end up inside an href value. If you genuinely need a < in a URL, it must be percent-encoded as %3C. Similarly, > should be encoded as %3E.
Example with the issue
<a href="https://example.com/search?q=<value>">Search</a>
How to fix it
Percent-encode the special characters in the URL:
<a href="https://example.com/search?q=%3Cvalue%3E">Search</a>
If you're generating URLs dynamically on the server side, use your language's built-in URL encoding function (e.g., encodeURIComponent() in JavaScript, urlencode() in PHP) to ensure all special characters are properly escaped before inserting them into href attributes.
The URL standard (defined by WHATWG) specifies a strict set of characters allowed in each part of a URL. A space character is not among them. When the validator encounters a literal space in an href value, it reports the error "Illegal character in scheme data: space is not allowed." This applies to spaces anywhere in the URL — the path, query string, fragment, or even after the scheme (e.g., https:).
While most modern browsers are forgiving and will attempt to fix malformed URLs by encoding spaces automatically, relying on this behavior is problematic for several reasons:
- Standards compliance: Invalid URLs violate the HTML specification, and markup that depends on browser error-correction is fragile and unpredictable.
- Accessibility: Assistive technologies, such as screen readers, may not handle malformed URLs the same way browsers do. This can result in broken links for users relying on these tools.
- Interoperability: Non-browser consumers of your HTML — search engine crawlers, link checkers, email clients, RSS readers, and APIs — may not perform the same auto-correction, leading to broken links or missed content.
- Copy-paste and sharing: When users copy a malformed URL from the source, the space can cause the link to break when pasted into other applications.
How to fix it
The fix depends on where the space appears:
- In the path or fragment: Replace each space with
%20. For example,/my file.htmlbecomes/my%20file.html. - In the query string: You can use
%20or, if the value is part ofapplication/x-www-form-urlencodeddata,+is also acceptable for spaces within query parameter values. However,%20is universally safe. - Programmatically: Use
encodeURI()in JavaScript to encode a full URL (it preserves structural characters like/,?, and#). UseencodeURIComponent()to encode individual query parameter values. On the server side, use your language's equivalent URL-encoding function.
If you're writing URLs by hand in HTML, simply find every space and replace it with %20. If URLs are generated dynamically (from a database, CMS, or user input), ensure your templating or server-side code encodes them before inserting into the markup.
Examples
Invalid — space in the path
<a href="https://example.com/docs/My Report.pdf">Download Report</a>
The literal space between "My" and "Report" triggers the validator error.
Fixed — space encoded as %20
<a href="https://example.com/docs/My%20Report.pdf">Download Report</a>
Invalid — space in a query parameter
<a href="https://example.com/search?q=hello world">Search</a>
Fixed — space encoded in the query string
<a href="https://example.com/search?q=hello%20world">Search</a>
Invalid — multiple spaces in different URL parts
<a href="https://example.com/my folder/page two.html?ref=some value#my section">Link</a>
Fixed — all spaces encoded
<a href="https://example.com/my%20folder/page%20two.html?ref=some%20value#my%20section">Link</a>
Encoding URLs with JavaScript
If you're building URLs dynamically, use the built-in encoding functions rather than doing manual string replacement:
<script>
// encodeURI encodes a full URL but preserves :, /, ?, #, etc.
const url = encodeURI("https://example.com/docs/My Report.pdf");
// Result: "https://example.com/docs/My%20Report.pdf"
// encodeURIComponent encodes a single value (for query params)
const query = encodeURIComponent("hello world");
// Result: "hello%20world"
</script>
Note that encodeURI() is appropriate for encoding a complete URL, while encodeURIComponent() should be used for individual components like query parameter values — it encodes characters such as / and ? that have structural meaning in a URL.
The W3C HTML Validator checks that URLs provided in href attributes conform to the URL specification. Square brackets ([ and ]) are reserved characters with very specific, limited uses in URLs — they are only permitted in the host portion of a URL to denote IPv6 addresses (e.g., http://[::1]/). When they appear elsewhere, such as in the scheme data, path, or query string without being percent-encoded, the URL is considered malformed.
This commonly happens in a few scenarios:
- Mailto links where someone wraps an email address in brackets, like
mailto:[user@example.com]. - Template variables that haven't been processed, leaving literal bracket syntax (e.g.,
{{,[,]) in the rendered HTML. - Manually constructed URLs where brackets are mistakenly used as part of the path or query string instead of being percent-encoded as
%5Band%5D.
Using invalid URLs can cause browsers to misinterpret the link destination, break navigation, or cause unexpected behavior. Assistive technologies such as screen readers also rely on well-formed URLs to correctly communicate link targets to users. Keeping your URLs standards-compliant ensures consistent, predictable behavior across all browsers and devices.
How to fix it
- Remove unnecessary brackets. If the brackets are not part of the actual data (e.g., decorative brackets around an email address), simply delete them.
- Percent-encode brackets when they are part of the data. If you genuinely need square brackets in a URL's path or query string, encode
[as%5Band]as%5D. - Check your templating engine output. If you use a templating system, inspect the final rendered HTML in a browser to make sure template syntax has been fully replaced with valid values.
Examples
Invalid: square brackets in a mailto URL
The brackets around the email address are not valid URL characters in this context.
<a href="mailto:[user@example.com]">Email Us</a>
Fixed: remove the brackets
<a href="mailto:user@example.com">Email Us</a>
Invalid: square brackets in a query string
<a href="https://example.com/search?filter[status]=active">Search</a>
Fixed: percent-encode the brackets
<a href="https://example.com/search?filter%5Bstatus%5D=active">Search</a>
Invalid: unprocessed template syntax in rendered HTML
If your templating engine fails to replace a variable, the final HTML may contain bracket characters:
<a href="mailto:[% user.email %]">Email Us</a>
Fixed: ensure the template renders a valid URL
Make sure the template variable resolves correctly. The rendered output should look like:
<a href="mailto:user@example.com">Email Us</a>
In your template source, this might be written as:
<a href="mailto:{{ user.email }}">Email Us</a>
The key is that the final HTML delivered to the browser must contain a valid, bracket-free URL (unless the brackets are properly percent-encoded). Always validate your rendered output, not just your template source, to catch issues like this.
The host in this link's URL has a label longer than 63 bytes, which is more than DNS allows for a single label.
A domain name such as docs.example.com is made of labels separated by dots: docs, example and com. RFC 1035 limits each label to 63 bytes, and the validator checks this limit when it parses the host of the URL. DNS can't resolve a host with a longer label, so the link leads nowhere.
The limit applies to the ASCII form of the label. Internationalized domain names are converted to Punycode (xn--...) before the check, and that encoding takes more bytes than the original characters, so a label with non-ASCII letters can go over the limit even when it looks shorter.
Real domains almost never have labels this long. The error usually comes from a missing slash between the domain and the path, which glues the path onto the top-level domain, or from a template that puts an ID or token where a subdomain should go. Paths and query strings have no per-segment limit like this, so moving the long part out of the host fixes the URL.
The validator reports a host that is too long as a whole (more than 255 bytes) with a different message.
Invalid example
The slash after example.com is missing, so the whole path becomes part of the last label:
<a href="https://example.comguides-to-writing-valid-html-for-accessible-websites-and-apps">Read the guide</a>
A long token used as a subdomain has the same problem:
<a href="https://5f2b8c1e9a7d4e6b8c3f1a2d9e7b5c4a6e8f1b3d5a7c9e2f4b6d8a1c3e5f7b9d.cdn.example.com/logo.png">Logo</a>
Valid example
Put the slash back, or move the token into the path:
<a href="https://example.com/guides-to-writing-valid-html-for-accessible-websites-and-apps">Read the guide</a>
<a href="https://cdn.example.com/5f2b8c1e9a7d4e6b8c3f1a2d9e7b5c4a6e8f1b3d5a7c9e2f4b6d8a1c3e5f7b9d/logo.png">Logo</a>
A URL is made up of several parts: scheme, host (domain), path, query, and fragment. While some of these parts allow certain special characters (often percent-encoded), the host portion has strict rules. Domain names follow the DNS naming conventions, which only permit ASCII letters (a-z, A-Z), digits (0-9), hyphens (-), and dots (.) as label separators. Spaces are categorically forbidden.
This validation error typically occurs in two scenarios:
- A literal space appears in the domain, e.g.,
http://my domain.com. This is often a typo or a copy-paste error. - A percent-encoded space (
%20) appears in the domain, e.g.,http://my%20domain.com. While%20is valid in URL paths and query strings, it is not valid in the host portion. Percent-encoding does not make a space legal in a domain name — it still resolves to a space character, which DNS cannot handle.
Why this is a problem
- Broken links: Browsers cannot resolve a domain with spaces to an actual server. Users clicking the link will get an error or be taken nowhere.
- Accessibility: Screen readers and assistive technologies may announce the link, but users will encounter a dead end, creating a frustrating experience.
- Standards compliance: The WHATWG URL Standard explicitly forbids spaces in the host component. The W3C validator flags this to help you catch what is almost certainly a mistake.
- SEO impact: Search engine crawlers will treat the URL as invalid and will not follow or index it.
How to fix it
- Check for typos: The most common fix is to correct the domain to the actual, valid domain name you intended.
- Replace spaces with hyphens: If the intended domain genuinely has a word separator, the standard convention is to use hyphens (e.g.,
my-domain.com). - Remove spaces entirely: Sometimes spaces are accidentally introduced and simply need to be removed (e.g.,
mydomain.com). - Check the path vs. host: If the space belongs in a file path or query parameter rather than the domain, make sure it's in the correct part of the URL and properly percent-encoded there.
Examples
❌ Literal space in the domain
<a href="http://my domain.com/page">Visit site</a>
❌ Percent-encoded space in the domain
<a href="http://my%20domain.com/page">Visit site</a>
✅ Fixed: use a hyphen in the domain
<a href="http://my-domain.com/page">Visit site</a>
✅ Fixed: remove the space entirely
<a href="http://mydomain.com/page">Visit site</a>
✅ Spaces are fine in the path (percent-encoded)
Note that %20 is valid in the path portion of a URL — just not in the domain:
<a href="http://mydomain.com/my%20page">Visit page</a>
Common mistake: space before or after the domain
Sometimes the space is hard to spot because it's at the beginning or end of the URL, or between the scheme and domain:
<!-- ❌ Trailing space in domain -->
<a href="http://mydomain.com /page">Visit site</a>
<!-- ✅ Fixed -->
<a href="http://mydomain.com/page">Visit site</a>
If your URLs are generated dynamically (e.g., from a CMS or database), make sure to trim whitespace from the domain portion before constructing the full URL. A quick way to catch these issues during development is to validate your HTML regularly with the W3C Markup Validation Service.
URLs must conform to the URL Living Standard, which forbids tab characters (U+0009) within the host/domain portion of a URL. While some browsers may silently strip tabs and still navigate to the intended destination, this behavior is not guaranteed and should not be relied upon.
This issue typically arises from one of the following scenarios:
- Copy-paste errors: Copying a URL from a document, email, or spreadsheet that inadvertently includes tab characters.
- Template or build tool formatting: A templating engine or code generator inserting whitespace (including tabs) into a URL string, especially when the URL is constructed across multiple lines.
- Manual typos: Accidentally pressing the Tab key while editing an
hrefvalue, particularly in editors that don't visualize whitespace.
Tab characters are invisible in most code editors by default, which makes this error frustrating to track down. Enabling "show whitespace" or "show invisible characters" in your editor can help you spot the offending character.
Why this matters
- Standards compliance: The HTML specification requires that
hrefvalues contain valid URLs. A tab in the domain makes the URL syntactically invalid. - Accessibility: Screen readers and assistive technologies parse
hrefvalues to announce link destinations. An invalid URL can lead to confusing or broken announcements. - Reliability: While major browsers tend to be forgiving and strip tabs before resolving URLs, some HTTP clients, crawlers, or older browsers may not. This can cause broken links in unexpected contexts like RSS readers, email clients, or web scrapers.
How to fix it
- Enable visible whitespace in your editor to locate tab characters.
- Search for tab characters in your
hrefvalues. In many editors, you can use a regex search for\twithin attribute values. - Remove the tab characters so the URL is a clean, continuous string with no embedded whitespace.
- If URLs are dynamically generated, inspect the code that builds them to ensure no tabs or other whitespace are concatenated into the domain.
Examples
❌ Incorrect: Tab character in the domain
In the example below, a tab character is embedded within the domain name (represented here as 	 for visibility, though in source code it would be an actual invisible tab):
<!-- The tab between "example" and ".com" causes the error -->
<a href="https://example .com/page">Visit Example</a>
Note: The tab character between example and .com is invisible in most editors but triggers the validation error.
✅ Correct: Clean URL with no whitespace
<a href="https://example.com/page">Visit Example</a>
❌ Incorrect: Tab introduced by multi-line URL construction in a template
This can happen when a URL is broken across lines in a template and tabs are used for indentation:
<a href="https://
example.com/page">Visit Example</a>
✅ Correct: URL on a single line with no embedded whitespace
<a href="https://example.com/page">Visit Example</a>
Tip: Finding hidden tabs
If you're having trouble locating the tab character, try pasting your href value into a tool that reveals character codes, or run a quick check in your browser's developer console:
// Check for tabs in a URL string
const url = document.querySelector('a').getAttribute('href');
console.log(url.includes('\t')); // true if a tab is present
console.log(JSON.stringify(url)); // shows \t explicitly in the output
Percent-encoding (also called URL encoding) is the mechanism defined by RFC 3986 for representing special or reserved characters in URLs. It works by replacing a character with a % sign followed by two hexadecimal digits that correspond to the character's byte value. For example, a space becomes %20, an ampersand becomes %26, and a literal percent sign becomes %25. When a browser or parser encounters % in a URL, it expects the next two characters to be valid hexadecimal digits so it can decode them back to the original character.
If the parser finds a % that is not followed by two hexadecimal digits, it cannot decode the sequence, and the URL is considered invalid. The W3C validator flags this as a bad value for the href attribute.
Common causes
- A literal
%that wasn't encoded. This is the most frequent cause. For instance, a URL containing a percentage value like50%in a query string — the%must be written as%25. - Truncated percent-encoded sequences. A sequence like
%2is incomplete because it only has one hex digit instead of two. - Invalid hex characters after
%. A sequence like%GZis invalid becauseGandZare not hexadecimal digits (valid hex digits are0–9andA–F). - Copy-pasting URLs from non-web sources. URLs pasted from documents, emails, or spreadsheets may contain unencoded special characters.
Why this matters
- Broken links. Browsers may interpret the malformed URL differently than intended, leading users to the wrong page or a 404 error.
- Standards compliance. The WHATWG URL Standard and the HTML specification require that
hrefvalues contain valid URLs. Malformed URLs violate these standards. - Accessibility. Screen readers and assistive technologies rely on well-formed URLs to provide accurate navigation information to users.
- Interoperability. While some browsers attempt error recovery on malformed URLs, behavior is not guaranteed to be consistent across all browsers and tools.
How to fix it
- Encode literal
%as%25. If the%is meant to appear as part of the URL's content (e.g., in a query parameter value), replace it with%25. - Complete any truncated sequences. If you intended a percent-encoded character like
%20, make sure both hex digits are present. - Use proper URL encoding functions. In JavaScript, use
encodeURIComponent()for query parameter values. In server-side languages, use the equivalent encoding function (e.g.,urllib.parse.quote()in Python,urlencode()in PHP).
Examples
Literal % not encoded
<!-- ❌ Bad: the % in "48%" is not followed by two hex digits -->
<a href="https://example.com?width=48%">48% width</a>
<!-- ✅ Good: the % is encoded as %25 -->
<a href="https://example.com?width=48%25">48% width</a>
Truncated percent-encoded sequence
<!-- ❌ Bad: %2 is incomplete — it needs two hex digits -->
<a href="https://example.com/path%2file">Download</a>
<!-- ✅ Good: %2F is a complete encoding for "/" -->
<a href="https://example.com/path%2Ffile">Download</a>
Invalid hexadecimal characters
<!-- ❌ Bad: %XY contains non-hexadecimal characters -->
<a href="https://example.com/search?q=%XYdata">Search</a>
<!-- ✅ Good: if the intent was a literal "%XY", encode the % -->
<a href="https://example.com/search?q=%25XYdata">Search</a>
Multiple unencoded % in a URL
<!-- ❌ Bad: both % signs are unencoded -->
<a href="https://example.com?min=10%&max=90%">Range</a>
<!-- ✅ Good: both % signs are properly encoded -->
<a href="https://example.com?min=10%25&max=90%25">Range</a>
The URL in this link has a port number above 65535, the largest value a network port can have.
In a URL such as https://example.com:8080/, the digits after the colon that follows the host are the port. Ports are 16-bit numbers, so the URL Standard rejects any port greater than 65535. A browser can't parse a URL like that, and clicking the link does nothing.
The usual cause is a phone link written as http://tel: followed by the number. The URL parser reads tel as a host name and the phone number as its port, and almost every phone number is larger than 65535. Phone links use the tel: scheme on its own, with no http:// in front, as defined in RFC 3966.
A short number doesn't make http://tel: correct. http://tel:12345 passes validation because 12345 is a valid port, but the link points at a web server called tel instead of dialing. A number containing + or - gets a different error, Illegal character in port. Whatever the validator says, drop the http:// from phone links.
When the URL really is meant to carry a port, check the digits for a typo: valid ports go from 0 to 65535.
Invalid example
<a href="http://tel:5551234567">Call us</a>
<a href="https://example.com:80800/">Open the dashboard</a>
Valid example
<a href="tel:+15551234567">Call us</a>
<a href="https://example.com:8080/">Open the dashboard</a>
The URL in the href attribute has a tab or a line break inside it, and a valid URL can't contain either.
HTML lets the href value start or end with whitespace, so line breaks before or after the URL are allowed. Inside the URL they are not: the URL Standard counts every tab, line feed and carriage return as a validation error. Browsers remove these characters before they follow the link, so the first link in the invalid example below still opens https://example.com/courses/web-design/. Scripts that read the value with getAttribute("href") get the raw string with the line break in it, and a tool that doesn't strip the break the way browsers do may request the wrong address.
The line break often arrives with the content. A URL pasted into a CMS link field can carry one, and a template that splits a long URL across lines writes the break into the attribute. Some systems output it as a character reference: 
 or for a line feed, 	 for a tab.
The validator shows the decoded value, so the message contains a real line break even when the source has 
. Search the source for those references as well as for literal breaks, then fix the stored value or strip tabs and line breaks from the URL before the template writes it.
Invalid example
<a href="https://example.com/courses/web-design
/">Web design course</a>
<a href="https://example.com/courses/
web-design/">Web design course</a>
Valid example
<a href="https://example.com/courses/web-design/">Web design course</a>
The URL in this href has a slash or backslash where the parser did not expect one, usually too many slashes after the scheme or a backslash standing in for the // separator.
After a scheme like https: the URL syntax expects exactly two forward slashes before the host: https://example.com. Adding a third slash (https:///example.com) leaves an empty host, and writing the separator with backslashes (https:\\example.com) uses a character the URL grammar does not allow there. In both cases the validator reports an unexpected slash or backslash.
This often comes from string concatenation that joins a base URL already ending in / with a path that also starts with /, or from copying a path that used backslashes. Browsers may paper over some of these, but the link can still resolve to the wrong place or fail in non-browser clients.
Invalid example
<a href="https:///example.com/page">Visit the page</a>
Valid example
<a href="https://example.com/page">Visit the page</a>
Keep exactly two forward slashes after the scheme, and use forward slashes throughout the URL.
A URL in an href attribute contains a username, password, or both (e.g., http://user:pass@example.com), which the W3C validator rejects because embedded credentials in URLs are a security risk.
Browsers have largely deprecated support for credentials in URLs. When a URL like http://user:password@example.com/page appears in HTML, the credentials are visible in the page source and can be leaked through referrer headers, proxy logs, or browser history. The WHATWG URL Standard defines username and password as URL components, but the HTML specification forbids their use in href attributes. Most modern browsers will strip the credentials or show a warning prompt rather than silently authenticate.
Remove the credentials from the URL. If authentication is required, handle it server side (redirects, session tokens, or an authentication flow) rather than embedding secrets in markup.
HTML examples
Invalid: URL with embedded credentials
<a href="https://admin:s3cret@example.com/dashboard">Dashboard</a>
Valid: URL without credentials
<a href="https://example.com/dashboard">Dashboard</a>
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.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries