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 decoding attribute of an <img> is set to something other than sync, async or auto.
decoding is a hint about when the browser should decode the image. async says the image can be decoded without delaying the rest of the content, sync asks for it to be decoded and shown together with the content around it, and auto, the default, leaves the choice to the browser. The value has to be one of those three lowercase keywords with nothing around it. A typo such as asynch, a keyword that belongs to another attribute such as lazy (that one goes in loading), uppercase ASYNC and an empty value all trigger this error.
When the reported value includes quotes, as in "async", the quotes are inside the value itself. That usually happens when the quotes around the value were HTML-encoded as ", often by a plugin or template that escaped markup a second time. " can't delimit an attribute, so the parser reads decoding="async" as an unquoted value and decodes both references into literal quotes. Wrapping the value in two sets of quotes, as in decoding='"async"', gives the same result. A value with only a trailing quote, such as async", means the opening quote is missing, and the validator also reports “"” in an unquoted attribute value.
Browsers treat an invalid value as auto, so the image still loads and displays, but the hint is lost. If you don't need a particular decoding mode, remove the attribute.
The " cause rarely affects decoding alone. If loading, width, height, srcset or sizes on the same <img> also report a stray ", fix the code that writes the tag instead of editing each attribute.
Invalid example
<img src="photo.jpg" alt="A red bicycle" width="600" height="400" decoding="async">
<img src="photo.jpg" alt="A red bicycle" width="600" height="400" decoding="asynch">
Valid example
<img src="photo.jpg" alt="A red bicycle" width="600" height="400" decoding="async">
The dir attribute accepts only ltr, rtl or auto on every element, so an empty value or any other word is invalid.
dir sets the base direction of an element's text: ltr for left-to-right scripts such as English, rtl for right-to-left scripts such as Arabic or Hebrew, and auto to let the browser pick the direction from the first strongly directional character in the content. The keywords are case-insensitive, so RTL passes. The validator rejects everything else: dir="", a bare dir with no value, a keyword with a stray space such as "rtl ", and made-up values such as none or right.
Browsers treat an invalid value as if the attribute were missing, so in most cases the element takes its parent's direction. HTML has no keyword for "inherit" or "no direction": leaving dir out already does that. So remove dir="none" or dir="" rather than looking for a value to put there.
The empty value usually comes from a template, CMS or rich text editor that prints dir="" when nobody picked a direction, which is why the error can repeat on every paragraph of a page. Change the template so it writes dir only when it has a real value. For text whose direction you can't know in advance, such as user comments, use dir="auto".
A few elements behave differently:
- On
<table>,diralso sets the column order. Withrtl, the first column sits on the right edge of the table. - On
<input>and<textarea>, it sets the direction of the text in the field. Fields where people may type in a right-to-left script, such as search boxes, work best withdir="auto". Adddirnameif the server needs that direction too: the form then submits it as an extra field, such asq.dir=rtl. - On
<meta>, it's allowed becausediris a global attribute, and on a<meta name>it sets the direction of thecontenttext. Often nobody wrote it on purpose, though. A double quote insidecontentends the value early, and each word after it becomes an attribute with an empty value. If one of those words is "dir", you get this error next to an "Attribute not allowed" error for the other words. Write double quotes inside the value as". - On
<bdo>,diris required and must beltrorrtl. Usingautothere triggers a different error.
Invalid example
<p dir="">Opening hours are Monday to Friday, 9:00 to 17:00.</p>
<table dir="none">
<tr>
<th>Size</th>
<th>Price</th>
</tr>
<tr>
<td>Small</td>
<td>4.50</td>
</tr>
</table>
<form action="/search">
<input type="search" name="q" aria-label="Search" dir="rtl ">
</form>
An unescaped quote in a page description turns the word "dir" into an empty attribute:
<meta name="description" content="How the "auto" value of the dir attribute picks a text direction">
Valid example
Remove the attribute where the element should follow the page, and use a valid keyword where it shouldn't:
<p>Opening hours are Monday to Friday, 9:00 to 17:00.</p>
<p lang="ar" dir="rtl">ساعات العمل من الاثنين إلى الجمعة</p>
<table>
<tr>
<th>Size</th>
<th>Price</th>
</tr>
<tr>
<td>Small</td>
<td>4.50</td>
</tr>
</table>
<form action="/search">
<input type="search" name="q" aria-label="Search" dir="auto" dirname="q.dir">
</form>
Escape the quotes inside content:
<meta name="description" content="How the "auto" value of the dir attribute picks a text direction">
disabled is a boolean attribute, so on every element that accepts it you write it bare, empty or as disabled="disabled", and a value like "true" or "false" is an error.
A boolean attribute can only hold the empty string or its own name, in any letter case. So disabled, disabled="", disabled="disabled" and disabled="DISABLED" all pass. The validator reports any other value with this message and quotes what it found: "true", "false", "1", "yes", "disabled " with a trailing space, and also "disabled" with quote marks inside the value. That last one shows up as “"disabled"” and comes from markup like disabled='"disabled"' or disabled=""disabled"", usually a template that wraps an already quoted value in another pair of quotes.
Browsers don't read the value. If the attribute is there, the element is disabled, so disabled="false" disables it just as disabled="true" does. To enable the element, remove the attribute. In JavaScript, set the property (field.disabled = false) or call removeAttribute("disabled"). Calling setAttribute("disabled", "false") leaves the element disabled.
The bad value usually comes from a form builder or template that prints a boolean setting straight into the markup, often with aria-disabled="true" next to it. The validator also warns that aria-disabled is unnecessary on an element that has disabled, so remove it while you're there.
Elements that don't take disabled at all, such as <div> or <a>, get a different error: Attribute “disabled” not allowed on element “div” at this point. Remove the attribute there instead of fixing its value.
What disabled does depends on the element:
<input>,<select>,<textarea>and<button>: the control can't be focused or used, and the browser leaves its name and value out of the submitted form data. It also skips validation, so arequiredfield stops blocking the form while it's disabled. If the user shouldn't edit a field but the server still needs its value, usereadonlyon a text<input>or a<textarea>, since read-only fields are submitted.<select>has noreadonlyattribute, so send its value in a hidden<input>instead.<option>and<optgroup>: a disabled option is greyed out and can't be picked, anddisabledon an<optgroup>disables every option inside it. A common use is the placeholder at the top of a drop-down, such as "Choose a size", markeddisabled selectedso it shows first but can't be chosen again. In arequired<select>, give itvalue=""as well, so the browser treats it as a placeholder and won't submit the form until the user picks a real option.<fieldset>: disables every form control inside it, except the ones in its first<legend>. A checkbox in the legend can therefore switch the rest of the group on and off.<link>:disabledis only allowed together withrel="stylesheet", and the browser doesn't load or apply that stylesheet until the attribute is removed. It's used for alternative stylesheets, such as a high-contrast theme, that a script turns on later withlink.disabled = false.
Invalid example
<form action="/order" method="post">
<label for="size">Size</label>
<select id="size" name="size" required>
<option value="" disabled="true" selected>Choose a size</option>
<option value="s">Small</option>
<option value="m">Medium</option>
<option value="l">Large</option>
</select>
<label for="coupon">Coupon code</label>
<input type="text" id="coupon" name="coupon" disabled="false">
<fieldset id="address" disabled="disabled ">
<legend>
<label>
<input type="checkbox" id="ship-elsewhere">
Ship to a different address
</label>
</legend>
<label for="street">Street</label>
<input type="text" id="street" name="street">
</fieldset>
<button type="submit">Place order</button>
</form>
Valid example
<form action="/order" method="post">
<label for="size">Size</label>
<select id="size" name="size" required>
<option value="" disabled selected>Choose a size</option>
<option value="s">Small</option>
<option value="m">Medium</option>
<option value="l">Large</option>
</select>
<label for="coupon">Coupon code</label>
<input type="text" id="coupon" name="coupon">
<fieldset id="address" disabled>
<legend>
<label>
<input type="checkbox" id="ship-elsewhere">
Ship to a different address
</label>
</legend>
<label for="street">Street</label>
<input type="text" id="street" name="street">
</fieldset>
<button type="submit">Place order</button>
</form>
<script>
document.getElementById("ship-elsewhere").addEventListener("change", (event) => {
document.getElementById("address").disabled = !event.target.checked;
});
</script>
The fetchpriority attribute of an <img> is set to something other than high, low or auto.
fetchpriority is a hint about how soon the browser should fetch the image compared with the other images on the page. high suits the main image at the top of the page, low suits images that start out of view, such as the later slides of a carousel, and auto, the default, leaves the choice to the browser. The value has to be one of those three keywords with nothing around it. A made-up level such as highest, a keyword that belongs to another attribute such as eager (that one goes in loading) and an empty value all trigger this error.
When the reported value includes quotes, as in "high", the quotes are inside the value itself. That usually happens when the quotes around the value were HTML-encoded as ", often by a plugin or template that escaped markup a second time. " can't delimit an attribute, so the parser reads fetchpriority="high" as an unquoted value and decodes both references into literal quotes. Wrapping the value in two sets of quotes, as in fetchpriority='"high"', gives the same result. A value with only a trailing quote, such as high", means the opening quote is missing, and the validator also reports “"” in an unquoted attribute value.
Browsers treat an invalid value as auto, so the image still loads, but at the default priority. A hero image meant to be high can then start downloading later than intended. If you don't need a particular priority, remove the attribute.
The " cause rarely affects fetchpriority alone. If decoding, width, height, srcset or sizes on the same <img> also report a stray ", fix the code that writes the tag instead of editing each attribute.
Invalid example
<img src="hero.jpg" alt="A mountain lake at sunrise" width="1200" height="600" fetchpriority="high">
<img src="hero.jpg" alt="A mountain lake at sunrise" width="1200" height="600" fetchpriority="highest">
Valid example
<img src="hero.jpg" alt="A mountain lake at sunrise" width="1200" height="600" fetchpriority="high">
The <label> element represents a caption for a form control. When you use the for attribute, its value must match the id of the form control it labels. According to the HTML specification, an id attribute value must not contain any whitespace characters — this includes spaces, tabs, line feeds, carriage returns, and form feeds. Since for must reference a valid ID, the same restriction applies to its value.
This error typically occurs when a developer uses a space-separated name (like "user name" or "first name") instead of a single continuous token. Browsers may fail to establish the programmatic association between the label and its form control when the for value contains whitespace. This directly impacts accessibility: screen readers rely on this association to announce the label text when a user focuses on the input. It also breaks the click-to-focus behavior where clicking a label moves focus to its associated control.
To fix this issue, replace any whitespace in the for attribute value with a valid character such as a hyphen (-), underscore (_), or camelCase. Make sure the id on the corresponding form control matches exactly.
Examples
Incorrect — whitespace in the for attribute
<form>
<label for="user name">Name</label>
<input type="text" id="user name">
</form>
The value "user name" contains a space, which makes it an invalid ID reference. The validator will report: Bad value "user name" for attribute "for" on element "label": An ID must not contain whitespace.
Correct — using an underscore instead of a space
<form>
<label for="user_name">Name</label>
<input type="text" id="user_name">
</form>
Correct — using a hyphen instead of a space
<form>
<label for="user-name">Name</label>
<input type="text" id="user-name">
</form>
Correct — using camelCase
<form>
<label for="userName">Name</label>
<input type="text" id="userName">
</form>
Incorrect — leading or trailing whitespace
Whitespace doesn't have to be in the middle of the value to trigger this error. Leading or trailing spaces also make the ID invalid:
<form>
<label for=" email">Email</label>
<input type="text" id=" email">
</form>
This can be easy to miss when values are generated dynamically or copied from another source. Trim the value to fix it:
<form>
<label for="email">Email</label>
<input type="text" id="email">
</form>
Alternative — wrapping the input inside the label
If you wrap the form control inside the <label> element, you don't need the for attribute at all. The association is implicit:
<form>
<label>
Name
<input type="text">
</label>
</form>
This approach avoids potential ID mismatches entirely, though explicit for/id pairing is often preferred for flexibility in layout and styling.
The HTML specification defines the height and width attributes on the <embed> element as valid non-negative integers. This means the value must consist only of digits — for example, 650 — with no units, whitespace, or other characters appended. When you write height="650px", the validator encounters the letter "p" where it expects either another digit or the end of the value, and it raises this error.
This is a common mistake because CSS requires units (e.g., 650px), and it's easy to assume HTML attributes work the same way. They don't. In HTML, the height attribute implicitly means CSS pixels, so writing 650 already means "650 pixels." Adding px is not only redundant — it makes the value invalid.
While most browsers are forgiving and will parse 650px correctly by stripping the unit, relying on this behavior is problematic. It violates the HTML specification, causes validation errors that can mask other real issues in your markup, and there's no guarantee every browser or embedded content handler will be equally tolerant. Standards compliance ensures consistent rendering across browsers and assistive technologies.
How to fix it
You have two approaches:
Remove the unit from the HTML attribute. Change
height="650px"toheight="650". This is the simplest fix and keeps your sizing in the markup.Move sizing to CSS. Remove the
heightattribute entirely and use a stylesheet or inlinestyleattribute instead. This approach is more flexible because CSS supports units like%,em,vh, and more.
The same rule applies to the width attribute on <embed>, as well as height and width on elements like <img>, <video>, <iframe>, and <canvas> — all of which expect plain integers in HTML.
Examples
❌ Invalid: unit included in the HTML attribute
The px suffix causes the validator error because the attribute value must be digits only.
<embed src="file.pdf" type="application/pdf" width="800" height="650px">
Other invalid variations include:
<embed src="file.pdf" type="application/pdf" height="100%">
<embed src="file.pdf" type="application/pdf" height="40em">
<embed src="file.pdf" type="application/pdf" height="50vh">
✅ Fixed: plain integer without a unit
Remove the unit so the value is a valid non-negative integer.
<embed src="file.pdf" type="application/pdf" width="800" height="650">
✅ Fixed: sizing moved to CSS
If you need units other than pixels, or prefer to keep presentation in your stylesheets, use CSS instead of the HTML attribute.
<embed class="pdf-viewer" src="file.pdf" type="application/pdf">
.pdf-viewer {
width: 800px;
height: 650px;
}
✅ Fixed: inline style as an alternative
You can also use the style attribute directly if a separate stylesheet isn't practical.
<embed src="file.pdf" type="application/pdf" style="width: 800px; height: 80vh;">
This is especially useful when you need viewport-relative or percentage-based sizing that HTML attributes can't express.
The height attribute on <iframe> is defined in the HTML specification as a "valid non-negative integer." This means the value must be a string of one or more digit characters (0 through 9) and nothing else. Unlike CSS properties, this attribute does not accept units like px or %, nor does it accept decimal values like 315.5. Even invisible characters such as leading or trailing spaces will trigger this validation error because the parser expects a digit and encounters something else.
This matters for several reasons. While browsers are generally forgiving and may still render the iframe correctly despite an invalid value, relying on error recovery behavior is fragile and may not work consistently across all browsers or future versions. Invalid attribute values can also cause unexpected results in automated tools, screen readers, and other user agents that parse HTML strictly. Writing valid, standards-compliant markup ensures predictable behavior everywhere.
Common causes of this error include:
- Adding CSS units to the attribute value (e.g.,
height="315px") - Using percentages (e.g.,
height="100%") - Decimal values (e.g.,
height="315.5") - Whitespace before or after the number (e.g.,
height=" 315"orheight="315 ") - Copy-paste artifacts introducing hidden characters
If you need percentage-based or decimal sizing, use CSS instead of the HTML attribute. The height attribute only accepts whole pixel values.
Examples
❌ Invalid: Using px unit in the attribute
<iframe width="560" height="315px" src="https://example.com/video"></iframe>
The validator sees the p character after 315 and reports the error.
❌ Invalid: Using a percentage
<iframe width="100%" height="100%" src="https://example.com/video"></iframe>
Percentage values are not allowed in the height attribute.
❌ Invalid: Decimal value
<iframe width="560" height="315.5" src="https://example.com/video"></iframe>
The decimal point is not a digit, so the validator rejects it.
❌ Invalid: Leading or trailing whitespace
<iframe width="560" height=" 315 " src="https://example.com/video"></iframe>
The space before 315 is encountered where a digit is expected.
✅ Valid: Digits only
<iframe width="560" height="315" src="https://example.com/video"></iframe>
The value 315 contains only digits and is a valid non-negative integer.
✅ Valid: Using CSS for percentage-based sizing
If you need the iframe to scale responsively, remove the height attribute and use CSS instead:
<iframe
width="560"
height="315"
src="https://example.com/video"
style="width: 100%; height: 100%;"
></iframe>
Or better yet, apply styles through a stylesheet:
<style>
.responsive-iframe {
width: 100%;
height: 400px;
}
</style>
<iframe class="responsive-iframe" src="https://example.com/video"></iframe>
This keeps the HTML attributes valid while giving you full control over sizing through CSS, including support for units like %, vh, em, and calc().
The height attribute of an <img> has a literal " character inside its value, which may only contain digits.
height takes a non-negative integer such as 109, with no quotes, units or spaces. The quotes around an attribute value are HTML syntax, not part of the value. When an extra " ends up inside it, the validator stops at that character and rejects the value.
A value that starts with the quote, such as "109", usually comes from one of two mistakes. In the first, the quotes around the value were HTML-encoded as ", often by a plugin or template that escaped markup a second time. " can't delimit an attribute, so the parser reads height="109" as an unquoted value and decodes both references into literal quotes. In the second, the value is wrapped in two sets of quotes, as in height='"109"'.
A value that ends with the quote, such as 109", means the opening quote is missing (height=109") or the quotes don't match (height='109"'). Without an opening quote, the validator also reports “"” in an unquoted attribute value.
Browsers read 109" as 109, so that case often looks fine. A value that starts with the quote fails to parse, and the browser ignores height. Without it, the browser can't work out the image's aspect ratio before the file loads, so it reserves no vertical space and the content below shifts once the image arrives.
The cause rarely affects height alone. If width, srcset or sizes on the same <img> also report a stray ", fix the code that writes the tag instead of editing each attribute.
Invalid example
<img src="logo.png" alt="Company logo" width="600" height="109">
<img src="logo.png" alt="Company logo" width="600" height=109">
Valid example
<img src="logo.png" alt="Company logo" width="600" height="109">
The height attribute of an <object> takes a number of CSS pixels written as digits only, so a unit such as px in height="800px" makes the value invalid.
The HTML standard defines width and height on <object> as dimension attributes, whose value must be a valid non-negative integer. The validator reads the value from the left and stops at the first character that isn't a digit. In 800px that is the p, and pt or pc stop at the same letter. Other units are reported by their first character (v in 80vh, e in 40em). A percentage such as 100% gets its own error, about the % sign.
Browsers read the leading digits and drop the rest, so height="800px" already renders 800 pixels tall. Deleting the unit leaves the layout as it is. The attribute can only express pixels, though. For a height in viewport units, ems or a percentage of the container, remove the attribute and set the CSS height property instead.
Invalid example
<object data="/docs/annual-report.pdf" type="application/pdf" width="600" height="800px"></object>
Valid example
<object data="/docs/annual-report.pdf" type="application/pdf" width="600" height="800"></object>
To size the object relative to the viewport, use CSS:
<object data="/docs/annual-report.pdf" type="application/pdf" style="width: 100%; height: 80vh;"></object>
The height attribute on <video> is defined in the HTML specification as a "valid non-negative integer." This means it must be a string of digits (e.g., "480") with no units, no decimal points, and no percentage signs. When you write something like height="50%", the W3C validator rejects it because % is not a digit character and percentage values are not part of the attribute's allowed syntax.
This same rule applies to the width attribute on <video>, as well as the width and height attributes on <img>, <canvas>, and other elements that accept pixel dimensions. The integer you provide represents a size in CSS pixels, so height="480" means 480 CSS pixels — no unit suffix is needed or allowed.
Why this matters
- Standards compliance: The HTML living standard explicitly defines these attributes as non-negative integers. Using percentages violates the spec and produces a validation error.
- Browser behavior: While some browsers may attempt to interpret a percentage value, the behavior is undefined and inconsistent. You cannot rely on it working correctly across all browsers and versions.
- Layout stability: Providing valid
widthandheightinteger values helps browsers reserve the correct aspect ratio for the video before it loads, reducing cumulative layout shift (CLS). Invalid values undermine this benefit.
How to fix it
- Replace the percentage value with a plain integer representing the desired pixel height.
- If you need percentage-based or responsive sizing, remove the percentage from the HTML attribute and use CSS instead. CSS
widthandheightproperties fully support percentage values, viewport units, and other flexible sizing methods. - Always keep integer
widthandheightattributes on the element when possible, even if you also use CSS for responsive sizing. This provides an intrinsic aspect ratio hint to the browser.
Examples
❌ Invalid: percentage value in the height attribute
<video controls width="100%" height="50%">
<source src="/media/video.webm" type="video/webm">
</video>
The validator reports: Bad value "50%" for attribute "height" on element "video": Expected a digit but saw "%" instead. The same error applies to the width="100%" attribute.
✅ Fixed: integer values for intrinsic dimensions
<video controls width="640" height="480">
<source src="/media/video.webm" type="video/webm">
</video>
Both width and height use plain integers representing CSS pixels. This is valid and gives the browser an aspect ratio hint (4:3 in this case).
✅ Fixed: responsive sizing with CSS
If you need the video to scale as a percentage of its container, use CSS for the sizing while keeping valid integer attributes for the aspect ratio:
<video controls width="640" height="360" style="width: 100%; height: auto;">
<source src="/media/video.webm" type="video/webm">
</video>
Here, width="640" and height="360" tell the browser the video's intrinsic aspect ratio (16:9), while the inline style (or an external stylesheet) makes the video fill 100% of its container width and scale its height proportionally. This approach is both valid HTML and fully responsive.
✅ Fixed: using a CSS class for responsive video
<style>
.responsive-video {
width: 100%;
max-width: 800px;
height: auto;
}
</style>
<video controls width="800" height="450" class="responsive-video">
<source src="/media/video.webm" type="video/webm">
</video>
This keeps the HTML valid, provides an aspect ratio hint, and achieves flexible, percentage-based sizing entirely through CSS.
The href attribute on an <a> element must contain a valid URL as defined by the WHATWG URL Standard. According to this standard, the forward slash (/) is the only recognized path segment delimiter. Backslashes (\) have no defined role in URL path syntax and are treated as invalid characters by the validator.
This issue most commonly occurs when developers copy file paths from Windows, which uses backslashes as its native path separator, directly into HTML. For example, copying a path like images\photos\sunset.jpg from Windows Explorer and pasting it into an href attribute will trigger this validation error.
While most modern browsers will silently normalize backslashes to forward slashes, relying on this behavior is problematic for several reasons:
- Standards compliance: Your HTML fails validation, which can mask other real issues in your code.
- Interoperability: Not all HTTP clients, crawlers, or tools normalize backslashes. Search engine bots, link checkers, or older browsers may fail to follow the link correctly.
- Portability: Code that depends on browser error correction is fragile and may break in unexpected environments, such as server-side rendering, email clients, or embedded web views.
- Accessibility: Screen readers and assistive technologies that parse
hrefvalues may not handle backslashes consistently, potentially breaking navigation for users who rely on these tools.
To fix the issue, simply replace every backslash (\) with a forward slash (/) in any URL used in an href attribute. This applies not only to <a> elements but to any attribute that expects a URL, such as src, action, or data.
Examples
Incorrect: backslash used as path delimiter
<a href="docs\guide\intro.html">Introduction</a>
Correct: forward slash used as path delimiter
<a href="docs/guide/intro.html">Introduction</a>
Incorrect: backslashes in an absolute URL
<a href="https://example.com\blog\2024\post.html">Read the post</a>
Correct: forward slashes in an absolute URL
<a href="https://example.com/blog/2024/post.html">Read the post</a>
Incorrect: mixed slashes
Sometimes a URL contains a mix of forward and backslashes, which still triggers the error:
<a href="assets/images\photo.jpg">View photo</a>
Correct: all forward slashes
<a href="assets/images/photo.jpg">View photo</a>
Tips for avoiding this issue
- Search and replace: If you're migrating content or working with paths generated on Windows, do a global find-and-replace of
\with/across your HTML files. - Editor settings: Many code editors can highlight or auto-fix invalid URL characters. Enable linting tools or HTML validation plugins to catch this early.
- Build tools: If your build process generates links from file system paths, ensure it normalizes path separators to forward slashes before writing them into HTML output.
- URL encoding: If you genuinely need a literal backslash character within a URL (which is extremely rare), it must be percent-encoded as
%5C. However, this is almost never the intended behavior when this validation error appears.
A valid URL consists of several parts: a scheme (like https), followed by ://, then the host, and optionally a path, query string, and fragment. The :// separator — a colon followed by two forward slashes — is a required part of the URL syntax for schemes like http and https. When one of these slashes is missing, the browser may fail to navigate to the intended destination, interpret the value as a relative path, or behave unpredictably across different environments.
This error commonly occurs due to simple typos, copy-paste mistakes, or programmatic URL construction where string concatenation goes wrong. While some browsers may attempt to correct malformed URLs, you should never rely on this behavior. A malformed href can break navigation entirely, cause security warnings, produce unexpected redirects, or confuse assistive technologies like screen readers that announce link destinations to users.
Beyond the missing-slash case, this error can also appear when other parts of the URL contain characters that aren't valid without proper encoding — for instance, spaces or special characters that should be percent-encoded. Always ensure your URLs conform to the URL Standard.
How to Fix
- Check the scheme separator: Verify that the protocol is followed by
://(colon and two slashes). For example,https://nothttps:/orhttps:. - Validate the full URL: Paste the URL into a browser's address bar to confirm it resolves correctly.
- Encode special characters: If the URL contains spaces or special characters, use proper percent-encoding (e.g., spaces become
%20). - Review dynamically generated URLs: If URLs are built through string concatenation or template logic, double-check that all parts are joined correctly.
Examples
Incorrect: Missing a slash after the scheme
<a href="https:/example.com">Visit Example</a>
The validator reports this because https:/example.com has only one slash after the colon instead of the required two.
Incorrect: Missing both slashes
<a href="https:example.com">Visit Example</a>
This is also invalid — the colon must be followed by // for https URLs.
Correct: Properly formatted URL
<a href="https://example.com">Visit Example</a>
Correct: URL with a path
<a href="https://example.com/blog/my-post">Read the Post</a>
Correct: URL with encoded spaces
<a href="https://example.com/search?q=hello%20world">Search</a>
Incorrect: Unencoded space in URL
<a href="https://example.com/my page">My Page</a>
Spaces are not valid in URLs. Use %20 or + (in query strings) instead:
<a href="https://example.com/my%20page">My Page</a>
The href value of a mailto: link contains a double quote ("), which the URL can only hold percent-encoded as %22.
The ilto: in the message is the tail of mailto:, and the check covers the whole address after it, so a " at the end of the address gets the same error as one at the start.
Usually the quotes were meant for the attribute and landed after the scheme, as in <a href=mailto:"info@example.com">. No quote follows the =, so HTML reads mailto:"info@example.com" as an unquoted value and copies both " characters into the URL. On that tag the validator also reports “"” in an unquoted attribute value. If a space follows the stray quote, the value ends at the space and the message shows only mailto:". Without a closing quote, a single " stays in front of the address.
Quoting the address on purpose doesn't help. In href='mailto:"info@example.com"' and href="mailto:"info@example.com"", the URL still starts with a literal " when the validator checks it. A display name in email header style, such as mailto:"Jane Doe" <info@example.com>, fails for the same reason: the URL holds only the address, and the name goes in the link text. For the rare address with a quoted local part, RFC 6068 asks for the quotes as %22, as in mailto:%22info%22@example.com.
Invalid example
<a href=mailto:"info@example.com">Email us</a>
Valid example
<a href="mailto:info@example.com">info@example.com</a>
A mailto: link in an href attribute contains a [ character that is not valid in a URI according to RFC 3986.
Square brackets ([ and ]) are reserved characters in URIs and must be percent-encoded when used outside their specific purpose (IPv6 address literals). If the email address or other part of the mailto: URI contains a [, it must be encoded as %5B. Similarly, ] must be encoded as %5D.
This error typically appears when a mailto: link includes square brackets in the subject, body, or display-related parts of the URL. Query parameters in mailto: links — such as ?subject= or ?body= — must have their values properly percent-encoded.
Invalid example
<a href="mailto:info@example.com?subject=[Action Required] Review">
Email us
</a>
Valid example
Percent-encode the square brackets in the query string:
<a href="mailto:info@example.com?subject=%5BAction%20Required%5D%20Review">
Email us
</a>
The [ becomes %5B, the ] becomes %5D, and spaces become %20. Most server side languages and JavaScript provide functions to handle this encoding automatically, such as encodeURIComponent() in JavaScript.
This tel: link has a double quote (") inside its href value, and " is not allowed in a URL.
The usual cause is quotes around the phone number instead of around the attribute value. In <a href=tel:"555-0100">, the value itself is unquoted, so the HTML parser keeps both quote marks as part of it and the URL becomes tel:"555-0100". For the same tag, the validator also reports “"” in an unquoted attribute value. Writing href='tel:"555-0100"', or using " entities, gives the same result, because " turns into a real " before the URL is checked.
For the number itself, RFC 3966 allows digits, a leading +, and the visual separators -, ., ( and ). Quote the whole attribute value and keep the number bare inside it. The link text can show the number in whatever format reads best. A value that holds two numbers has to become two links. Tel: with a capital T is fine, since scheme names are case-insensitive, though most pages write tel:.
Invalid example
<a href=tel:"+1-555-0100">Call us</a>
Valid example
<a href="tel:+1-555-0100">+1 555-0100</a>
A tel: URI in an href attribute must not contain spaces. The phone number should be written as a continuous string of digits, optionally prefixed with + for the country code.
The tel: URI scheme is defined in RFC 3966. It allows digits, hyphens, dots, and parentheses as visual separators, but spaces are not permitted. Browsers may still dial the number if spaces are present, but the markup is technically invalid.
A common approach is to use the full international number with no spaces in the href value while keeping a human-readable format in the visible link text. If you want visual separators in the href, use hyphens or dots instead of spaces.
Invalid example
<a href="tel:+1 555 123 4567">Call us</a>
Valid examples
<a href="tel:+15551234567">+1 555 123 4567</a>
<a href="tel:+1-555-123-4567">+1 555 123 4567</a>
URLs follow a strict syntax defined by RFC 3986 and the URL Living Standard. Only a specific set of characters are allowed to appear unencoded in a URL. Curly braces ({ and }) are among the characters that fall outside this permitted set. When the W3C validator encounters a raw { or } in an href value, it reports the error: Bad value for attribute "href" on element "a": Illegal character in fragment.
This issue commonly arises in a few scenarios:
- Server-side or client-side template placeholders left unresolved in the rendered HTML (e.g.,
{id},{{slug}}). - URLs copied from API documentation that use curly braces to indicate variable segments (e.g.,
/users/{userId}/posts). - Malformed or auto-generated URLs where curly braces were included by mistake.
Why This Matters
Standards compliance: The HTML specification requires that href values conform to valid URL syntax. Curly braces violate this requirement, producing invalid HTML.
Browser inconsistency: While most modern browsers will attempt to handle URLs with illegal characters by silently encoding them, this behavior is not guaranteed across all browsers or versions. Relying on browser error correction can lead to unpredictable results.
Accessibility and interoperability: Assistive technologies, web crawlers, and other tools that parse HTML may not handle illegal URL characters gracefully. Invalid URLs can break link extraction, bookmarking, and sharing functionality.
Debugging difficulty: If curly braces appear in your rendered HTML, it often signals that a template variable was not properly resolved, which may point to a deeper bug in your application logic.
How to Fix It
The fix depends on why the curly braces are there:
If the curly braces are literal characters that should be part of the URL, replace them with their percent-encoded equivalents:
{becomes%7Band}becomes%7D.If the curly braces are template placeholders (e.g.,
{userId}), ensure your server-side or client-side code resolves them to actual values before the HTML is sent to the browser. The rendered HTML should never contain unresolved template variables.If the curly braces were included by mistake, simply remove them.
Examples
Incorrect: Raw curly braces in href
<a href="https://example.com/api/users/{userId}/profile">View Profile</a>
This triggers the validation error because { and } are illegal URL characters.
Correct: Percent-encoded curly braces
If the curly braces are meant to be literal parts of the URL:
<a href="https://example.com/api/users/%7BuserId%7D/profile">View Profile</a>
Correct: Resolved template variable
If the curly braces were template placeholders, ensure your templating engine resolves them before rendering. The final HTML should look like:
<a href="https://example.com/api/users/42/profile">View Profile</a>
Incorrect: Curly braces in a fragment identifier
<a href="https://example.com/docs#section-{name}">Jump to Section</a>
Correct: Percent-encoded fragment
<a href="https://example.com/docs#section-%7Bname%7D">Jump to Section</a>
Incorrect: Curly braces in query parameters
<a href="https://example.com/search?filter={active}">Active Items</a>
Correct: Percent-encoded query parameter
<a href="https://example.com/search?filter=%7Bactive%7D">Active Items</a>
Using JavaScript for dynamic URLs
If you need to build URLs dynamically with values that might contain special characters, use encodeURIComponent() in JavaScript rather than inserting raw values into href attributes:
<a id="dynamic-link" href="https://example.com">Dynamic Link</a>
<script>
var value = "{some-value}";
var link = document.getElementById("dynamic-link");
link.href = "https://example.com/path?param=" + encodeURIComponent(value);
</script>
This ensures that any special characters, including curly braces, are automatically percent-encoded in the resulting URL.
A URL fragment identifier is the part of a URL that follows the # symbol, typically used to link to a specific section within a page. The URL specification (RFC 3986 and the WHATWG URL Standard) defines a strict set of characters that are permitted in fragments. The > character (greater-than sign) is among those that are not allowed to appear literally. When the W3C HTML Validator encounters > inside an href value — whether in the fragment or elsewhere in the URL — it raises this error.
In most cases, the > character appears in a URL by accident — for example, from a copy-paste error, a typo where the closing > of the tag accidentally ends up inside the attribute value, or a malformed template expression. Less commonly, a developer may genuinely need the > character as part of the URL content.
Why This Matters
- Broken links: Browsers may interpret the
>as the end of the HTML tag or handle the URL unpredictably, leading to broken navigation. - Standards compliance: Invalid URLs violate both the HTML specification and URL syntax standards, causing validation failures.
- Accessibility: Screen readers and other assistive technologies rely on well-formed markup. A malformed
hrefcan confuse these tools and prevent users from reaching the intended destination. - Interoperability: While some browsers may silently correct or ignore the invalid character, others may not. Valid URLs guarantee consistent behavior everywhere.
How to Fix It
- If the
>is a typo or copy-paste error, simply remove it from thehrefvalue. This is the most common scenario. - If the
>is intentionally part of the fragment or URL, replace it with its percent-encoded equivalent:%3E. - Review your templates or CMS output — this error often originates from template engines or content management systems that inject malformed values into
hrefattributes.
Examples
Accidental > in the URL path
A common mistake is accidentally including the tag's closing > inside the attribute value:
<!-- ❌ Invalid: ">" is not allowed in the URL -->
<a href="/page.php>">Read more</a>
Remove the stray >:
<!-- ✅ Valid: clean URL without illegal character -->
<a href="/page.php">Read more</a>
Illegal > in a fragment identifier
The > can also appear inside the fragment portion of the URL:
<!-- ❌ Invalid: ">" in the fragment -->
<a href="/docs#section->overview">Go to overview</a>
If the > is unintentional, remove it:
<!-- ✅ Valid: fragment without illegal character -->
<a href="/docs#section-overview">Go to overview</a>
If the > is genuinely needed in the fragment, percent-encode it:
<!-- ✅ Valid: ">" encoded as %3E -->
<a href="/docs#section-%3Eoverview">Go to overview</a>
Query string or path containing >
The same rule applies outside of fragments. If > appears anywhere in the URL, encode it:
<!-- ❌ Invalid: ">" in query parameter -->
<a href="/search?filter=price>100">Expensive items</a>
<!-- ✅ Valid: ">" percent-encoded as %3E -->
<a href="/search?filter=price%3E100">Expensive items</a>
Template output errors
If you are using a server-side template or JavaScript framework, ensure that dynamic values inserted into href are properly URL-encoded. For example, in a template that generates links:
<!-- ❌ Invalid: unencoded dynamic value -->
<a href="/results#filter=>50">View results</a>
<!-- ✅ Valid: properly encoded value -->
<a href="/results#filter=%3E50">View results</a>
Most server-side languages provide built-in URL encoding functions (e.g., encodeURIComponent() in JavaScript, urlencode() in PHP, urllib.parse.quote() in Python) that will handle this automatically. Always use these functions when inserting dynamic content into URLs.
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>
A backslash (\) is not a valid character in a URL fragment and must be replaced with a forward slash (/) or percent-encoded.
The href attribute on an <a> element must contain a valid URL according to the URL Living Standard. The fragment portion of a URL — the part after the # symbol — follows the same rule: it can contain most characters, but the backslash (\) is explicitly forbidden as a bare character.
This commonly happens when copying file paths from Windows, which uses backslashes as directory separators, and pasting them into an href. Browsers may silently convert \ to /, but the markup is still invalid.
To fix this, replace every \ with / in the URL. If for some reason you actually need a literal backslash in the fragment, percent-encode it as %5C.
HTML Examples
❌ Invalid: backslash in the fragment
<a href="page.html#section\one">Link</a>
✅ Fixed: use a forward slash or percent-encoding
<!-- Option 1: Replace with forward slash -->
<a href="page.html#section/one">Link</a>
<!-- Option 2: Percent-encode the backslash -->
<a href="page.html#section%5Cone">Link</a>
A | (pipe) character in the fragment portion of a URL is not allowed without percent-encoding it as %7C.
The fragment is the part of a URL that comes after the # symbol. According to RFC 3986, fragments can only contain unreserved characters (A-Z, a-z, 0-9, -, ., _, ~), percent-encoded characters, sub-delimiters (!, $, &, ', (, ), *, +, ,, ;, =), :, @, /, and ?.
The pipe character | is not in any of those sets, so it must be percent-encoded as %7C when used in a URL fragment.
This issue commonly appears when fragment identifiers are auto-generated from headings or content that contains |, such as table-related text or wiki-style page anchors.
Invalid example
<a href="/page#section|intro">Go to section</a>
Valid example
Replace | with its percent-encoded equivalent %7C:
<a href="/page#section%7Cintro">Go to section</a>
If you control the target element's id, a better approach is to remove the pipe character from the id altogether and use only unreserved characters:
<h2 id="section-intro">Section intro</h2>
<a href="/page#section-intro">Go to section</a>
The fragment portion of a URL (everything after the # symbol) follows the same encoding rules as the rest of the URL — literal space characters are not permitted. When a browser encounters a space in a URL fragment, it may try to correct it automatically, but this behavior is not guaranteed across all browsers and contexts. Relying on browser error-correction leads to fragile links that may break unpredictably.
This issue matters for several reasons. First, it produces invalid HTML that fails W3C validation. Second, fragment navigation (jumping to a specific section of a page) may not work correctly if the browser doesn't auto-correct the space. Third, assistive technologies like screen readers rely on well-formed URLs to announce link destinations accurately. Finally, tools that parse or process HTML programmatically — such as crawlers, link checkers, and content management systems — may misinterpret or reject malformed URLs.
The most common scenario for this error is linking to an id attribute on the same page or another page where the id contains spaces. However, it's worth noting that id values themselves cannot contain spaces in valid HTML (a space in an id would make it multiple invalid tokens). So if you're writing both the link and the target, the best fix is often to correct the id itself by using hyphens or underscores instead of spaces.
How to Fix It
There are two main approaches:
- Percent-encode the spaces — Replace each space with
%20in thehrefvalue. - Use space-free identifiers — Change the target
idto use hyphens or camelCase, then update the fragment to match.
The second approach is strongly preferred because it fixes the root problem and produces cleaner, more readable markup.
Examples
❌ Invalid: Space in the fragment
<a href="https://example.com/page#some term">Go to section</a>
<a href="#my section">Jump to My Section</a>
✅ Fixed: Percent-encode the space
If you cannot control the target id (e.g., linking to an external page), percent-encode the space:
<a href="https://example.com/page#some%20term">Go to section</a>
✅ Better fix: Use a hyphenated id and matching fragment
When you control both the link and the target, use a space-free id:
<h2 id="my-section">My Section</h2>
<p>Some content here.</p>
<a href="#my-section">Jump to My Section</a>
❌ Invalid: Space in fragment linking to another page
<a href="/docs/getting-started#quick start guide">Quick Start Guide</a>
✅ Fixed: Matching hyphenated id
<!-- On the target page (/docs/getting-started): -->
<h2 id="quick-start-guide">Quick Start Guide</h2>
<!-- On the linking page: -->
<a href="/docs/getting-started#quick-start-guide">Quick Start Guide</a>
A note on id naming conventions
Since fragment identifiers reference id attributes, adopting a consistent id naming convention avoids this issue entirely. Common patterns include:
<!-- Hyphens (most common, used by many static site generators) -->
<section id="getting-started">
<!-- camelCase -->
<section id="gettingStarted">
<!-- Underscores -->
<section id="getting_started">
All three are valid and will never trigger a space-related validation error in your fragment links.
A [ in the fragment of a link's URL, the part after #, has to be percent-encoded as %5B.
The URL Standard only allows square brackets around an IPv6 address in the host, as in http://[::1]/. Anywhere else, including the fragment, a valid URL writes [ as %5B and ] as %5D. Browsers still follow a link with raw brackets, but the href value isn't a valid URL, and the validator reports the first [ it finds.
This often comes from long links copied out of a browser's address bar, such as map or search pages that keep coordinates or filters after the #. When the URL is that long (around 200 characters or more), the validator leaves it out of the message, which then reads Bad value for attribute "href" with no value at all. To find the link, look for an href with a [ after its #.
Encoding the brackets doesn't break links to elements on the same page. Browsers percent-decode the fragment when they look for a matching id, so href="#step%5B2%5D" still scrolls to id="step[2]". For a link to another site, open the encoded URL once to check that the target page still reads its fragment correctly.
Invalid example
<a href="https://example.com/map#view:[40.64,-8.63]">Open the map</a>
Valid example
<a href="https://example.com/map#view:%5B40.64,-8.63%5D">Open the map</a>
The href value on the <a> element has a literal ^ (caret) in its path, and a URL can only carry that character percent-encoded as %5E.
The URL standard doesn't list ^ among the characters a URL can contain. Browsers still follow the link, but the markup is invalid.
The caret usually comes from a file name. A document saved as meeting-minutes-^2.pdf and uploaded to a CMS keeps the caret in its address, and every link to it repeats it. Rename the file without the caret and update the links, adding a redirect from the old address if other sites link to it. If the file has to keep its name, write the caret as %5E in the href. The server decodes %5E back to ^ when it looks up the file, so the encoded link still opens the same document.
A caret in the query string or the fragment gets a different message, ending in "Illegal character in query" or "Illegal character in fragment". 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="/files/meeting-minutes-^2.pdf">Meeting minutes (PDF)</a>
Valid example
Rename the file so its name has no caret:
<a href="/files/meeting-minutes-2.pdf">Meeting minutes (PDF)</a>
If the file name can't change, percent-encode the caret:
<a href="/files/meeting-minutes-%5E2.pdf">Meeting minutes (PDF)</a>
The href of this link contains a curly brace, usually from template syntax like {{ ... }} that reached the HTML without being replaced by a real URL.
Curly braces aren't allowed in URLs. When a placeholder such as {{ menu.link }} or {id} ends up in the page, the browser gets the placeholder text instead of an address. A value like {{ menu.link }}, with no scheme or leading slash, is a relative URL, so the brace counts as part of the path. That's why the validator mentions a path segment. A stray } in the path gets the same message with } in place of {. A brace in the query string or the fragment is reported with a different message.
Client-side frameworks often cause this. In AngularJS, href="{{ menu.link }}" puts the raw expression in the HTML, and anything that reads the page before the script runs sees it: the validator, a crawler, or a visitor whose JavaScript failed to load. AngularJS has the ng-href directive for this case. Write it as data-ng-href so the attribute is valid HTML, and AngularJS sets href once the expression has a value. Until then the link has no href and can't be reached with the keyboard, so rendering the final URL on the server is the more reliable fix.
If the braces are meant to be literal characters in the URL, percent-encode them: { as %7B and } as %7D.
Invalid example
<a href="{{ menu.link }}">Products</a>
Valid example
The server renders the final URL:
<a href="/products/">Products</a>
Valid example with AngularJS
<a data-ng-href="{{ menu.link }}">Products</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