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 listbox role is the implicit ARIA role for a <select> element only when it has a multiple attribute or a size attribute greater than 1. A standard single-selection <select> (dropdown) has an implicit role of combobox, so explicitly assigning role="listbox" to it creates a conflict.
When a <select> element has no multiple attribute and no size greater than 1, browsers render it as a collapsed dropdown — a combobox. The listbox role describes a widget where all options are persistently visible, which matches the behavior of a multi-select or a select with a visible size greater than 1. Applying role="listbox" to a standard dropdown misrepresents the control to assistive technologies.
You have a few options to fix this: remove the role="listbox" entirely (since the browser already assigns the correct implicit role), add the multiple attribute, or set size to a value greater than 1.
Incorrect Example
<select role="listbox" name="color">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
Fixed Examples
Remove the explicit role and let the browser handle it:
<select name="color">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
Or, if you genuinely need role="listbox", use multiple or size greater than 1:
<select role="listbox" name="color" multiple>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
<select role="listbox" name="color" size="3">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
In most cases, simply removing role="listbox" is the best fix. The implicit ARIA roles already convey the correct semantics to assistive technologies without any extra attributes.
Many HTML elements have built-in (implicit) ARIA roles defined by the WAI-ARIA specification. The <li> element natively carries the listitem role when it is a child of a <ul>, <ol>, or <menu> element. Adding role="listitem" explicitly doesn't change behavior, but it clutters your markup and signals a misunderstanding of how semantic HTML and ARIA interact. This falls under the first rule of ARIA use: "If you can use a native HTML element with the semantics and behavior you require already built in, do so, instead of re-purposing an element and adding an ARIA role."
Redundant ARIA roles create several problems:
- Maintenance burden — Extra attributes add noise to your code, making it harder to read and maintain.
- Potential confusion — Other developers may wonder if the explicit role was added intentionally to override something, leading to uncertainty during code reviews.
- Validator warnings — Tools like the W3C HTML Validator flag these redundancies, and accumulating unnecessary warnings can obscure real issues that need attention.
The ARIA listitem role is designed for situations where you cannot use semantic HTML — for instance, when you need to create a list-like structure from generic elements like <div> or <span>. In those cases, you would pair role="list" on the container with role="listitem" on each child. But when you're already using <ul>, <ol>, or <menu> with <li> children, the ARIA roles are built in and should not be repeated.
To fix this, simply remove the role="listitem" attribute from your <li> elements. If you also have role="list" on a <ul> or <ol>, remove that too — it's equally redundant.
Examples
❌ Redundant role on <li> elements
<ul role="list">
<li role="listitem">Apples</li>
<li role="listitem">Bananas</li>
<li role="listitem">Cherries</li>
</ul>
Both role="list" on the <ul> and role="listitem" on each <li> are unnecessary because these elements already carry those roles implicitly.
✅ Clean semantic HTML without redundant roles
<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Cherries</li>
</ul>
The <ul> and <li> elements provide all the accessibility semantics needed without any explicit ARIA attributes.
✅ Using ARIA roles on non-semantic elements (when necessary)
If for some reason you cannot use native list elements, ARIA roles are appropriate on generic elements:
<div role="list">
<div role="listitem">Apples</div>
<div role="listitem">Bananas</div>
<div role="listitem">Cherries</div>
</div>
This is the intended use case for role="listitem" — adding list semantics to elements that don't have them natively. However, using semantic <ul>/<ol> with <li> is always preferred when possible.
The longdesc attribute was originally designed to point to a URL containing a detailed description of an element's content, primarily as an accessibility feature for screen reader users. On <iframe> elements, it was intended to describe the framed content for users who couldn't perceive it directly. However, the attribute was poorly implemented across browsers, rarely used by assistive technologies, and was ultimately removed from the HTML specification for <iframe> elements.
Using obsolete attributes causes W3C validation errors and can create a false sense of accessibility. Since browsers and assistive technologies don't reliably process longdesc on iframes, users who need the description may never actually reach it. A visible link, on the other hand, is universally accessible — it works for all users regardless of their browser, device, or assistive technology.
The fix is straightforward: remove the longdesc attribute from the <iframe> and place a regular <a> element near the iframe that links to the description page. This approach is more robust because the link is visible, discoverable, and works everywhere.
Examples
❌ Obsolete: Using longdesc on an <iframe>
<iframe src="report.html" title="Annual report" longdesc="report-description.html"></iframe>
This triggers the validation error because longdesc is no longer a valid attribute on <iframe>.
✅ Fixed: Using a visible link instead
<iframe src="report.html" title="Annual report"></iframe>
<p>
<a href="report-description.html">Read a detailed description of the annual report</a>
</p>
The longdesc attribute is removed, and a descriptive link is placed adjacent to the iframe so all users can access it.
✅ Alternative: Wrapping in a <figure> for better semantics
For a more structured approach, you can use a <figure> element with a <figcaption> to associate the description link with the iframe:
<figure>
<iframe src="report.html" title="Annual report"></iframe>
<figcaption>
Annual report overview.
<a href="report-description.html">Read the full description</a>.
</figcaption>
</figure>
This groups the iframe and its caption together semantically, making the relationship between them clear to both sighted users and assistive technologies.
✅ Alternative: Using aria-describedby for additional context
If you want to provide a short inline description that assistive technologies can announce automatically, you can use aria-describedby:
<p id="report-desc">
This iframe contains the interactive annual report for 2024.
<a href="report-description.html">Read the full description</a>.
</p>
<iframe src="report.html" title="Annual report" aria-describedby="report-desc"></iframe>
This links the iframe to the descriptive paragraph programmatically. Screen readers will announce the content of the referenced element when the iframe receives focus, while the visible link remains available to all users.
Key Takeaways
- Always include a
titleattribute on<iframe>elements to describe their purpose — this is an important baseline accessibility practice. - Replace
longdescwith a visible<a>element that links to the long description. - Place the link near the iframe so users can easily find it.
- Consider using
<figure>and<figcaption>oraria-describedbyfor stronger semantic association between the iframe and its description.
The longdesc attribute dates back to HTML4, where it accepted a URL pointing to a separate page (or section of a page) containing a detailed description of the image. The idea was to supplement the short text in the alt attribute with a more comprehensive explanation, particularly useful for complex images like charts, diagrams, or infographics.
HTML5 made longdesc obsolete for several reasons. Browser support was inconsistent — most browsers never exposed the attribute in a way that was easily discoverable by users. Many developers misused it by placing literal descriptions in the attribute instead of URLs, or left it pointing to broken links. Because the attribute was invisible in the rendered page, there was no visual indication that a longer description existed, making it practically useless for sighted users and unreliable for assistive technology users.
The recommended replacements are more robust and accessible:
- Wrap the image in an
aelement (or place a link nearby) that points to the description page. This makes the link visible and usable by everyone. - Use
aria-describedbyto reference a description that already exists on the same page. This is ideal when the detailed description is displayed alongside the image. - Use a
figurewithfigcaptionto associate a visible caption or description directly with the image.
These approaches are better for accessibility because they work reliably across browsers and assistive technologies, and they make the description discoverable to all users, not just those using specific screen readers that happened to support longdesc.
Examples
❌ Obsolete: using longdesc
<img
src="cat.jpg"
alt="Smiling cat sitting on a windowsill"
longdesc="descriptions/smiling-cat.html">
This triggers the validation error because longdesc is no longer a valid attribute on img in HTML5.
✅ Fix: wrap the image in a link
The simplest replacement is to make the image itself a link to the description:
<a href="descriptions/smiling-cat.html">
<img src="cat.jpg" alt="Smiling cat sitting on a windowsill">
</a>
✅ Fix: provide a separate link near the image
If you don't want the image itself to be clickable, place a visible link nearby:
<figure>
<img src="chart.png" alt="Quarterly revenue chart for 2024">
<figcaption>
Quarterly revenue chart.
<a href="descriptions/revenue-chart.html">View detailed description</a>
</figcaption>
</figure>
✅ Fix: use aria-describedby for on-page descriptions
When the long description is already on the same page, reference it with aria-describedby:
<figure>
<img
src="chart.png"
alt="Quarterly revenue chart for 2024"
aria-describedby="chart-description">
<figcaption id="chart-description">
Revenue grew from $2.1M in Q1 to $3.8M in Q4, with the largest
quarter-over-quarter increase occurring between Q2 and Q3.
</figcaption>
</figure>
This approach keeps the description visible on the page and programmatically associates it with the image for screen readers.
Choosing the right approach
| Scenario | Recommended approach |
|---|---|
| Description is on a separate page | Wrap image in an a element or add a nearby link |
| Description is visible on the same page | Use aria-describedby pointing to the description's id |
| Image needs a brief visible caption | Use figure with figcaption |
| Complex image (chart, diagram, infographic) | Combine figure, figcaption, and a link to a full description |
In all cases, make sure the alt attribute still provides a meaningful short description. The long description supplements alt — it doesn't replace it.
The <main> element serves a very specific purpose in HTML: it identifies the primary content of the document's <body> — the content that is directly related to or expands upon the central topic of the page. Because of this document-level role, the HTML specification restricts where <main> can appear. It must not be a descendant of <article>, <aside>, <header>, <footer>, or <nav>. These are all sectioning or structural elements that represent subsets of the page, and nesting <main> inside them creates a semantic contradiction — you'd be saying "the main content of the whole page lives inside this one sub-section."
The <article> element, by contrast, represents a self-contained composition — something like a blog post, a news story, a forum post, or a comment. Articles are meant to be independently distributable or reusable. They logically live within the main content area of a page, not around it.
This distinction matters for accessibility. Screen readers and assistive technologies use the <main> landmark to let users skip directly to the primary content of a page. When <main> is incorrectly nested inside an <article>, assistive technologies may misinterpret the document structure, making navigation confusing or unreliable. Search engines also rely on semantic HTML to understand page structure, so incorrect nesting can affect how your content is indexed.
To fix this issue, move the <main> element out of the <article> and make it a direct child of <body> (or of a non-sectioning element like <div>). Then place your <article> elements inside <main>. Also remember that only one visible <main> element should exist per page (additional <main> elements must have the hidden attribute).
Examples
Incorrect: <main> nested inside <article>
This triggers the validation error because <main> is a descendant of <article>:
<article>
<main>
<h1>My Blog Post</h1>
<p>This is the post content.</p>
</main>
</article>
Incorrect: <main> deeply nested inside <article>
The error also triggers when <main> is an indirect descendant — it doesn't need to be a direct child:
<article>
<div class="wrapper">
<main>
<h1>My Blog Post</h1>
<p>This is the post content.</p>
</main>
</div>
</article>
Correct: <article> inside <main>
Invert the relationship so that <main> wraps the article content:
<main>
<article>
<h1>My Blog Post</h1>
<p>This is the post content.</p>
</article>
</main>
Correct: Multiple articles inside <main>
A typical page layout with <main> containing several articles alongside other content:
<main>
<h1>Latest Posts</h1>
<article>
<h2>First Post</h2>
<p>Content of the first post.</p>
</article>
<article>
<h2>Second Post</h2>
<p>Content of the second post.</p>
</article>
</main>
Correct: Full document structure
A complete valid document showing the proper placement of <main> as a direct child of <body>:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blog - Latest Posts</title>
</head>
<body>
<header>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<h1>Latest Posts</h1>
<article>
<h2>My Blog Post</h2>
<p>This is the post content.</p>
</article>
</main>
<footer>
<p>© 2024 My Blog</p>
</footer>
</body>
</html>
The key rule to remember: <main> represents the page's primary content and sits at the top of your content hierarchy. Sectioning elements like <article>, <aside>, and <nav> are components within that hierarchy and belong inside or alongside <main> — never around it.
The <main> element identifies the primary content of a page — the content that is directly related to or expands upon the central topic of the document. According to the WHATWG HTML living standard, a <main> element must not appear as a descendant of another <main> element. This rule exists because the semantic purpose of <main> is to mark a single, unique content region; nesting it creates a contradictory structure where one "primary content area" exists inside another.
This matters for several important reasons:
- Accessibility: Screen readers and other assistive technologies use the
<main>landmark to allow users to skip directly to the primary content. When multiple or nested<main>elements exist, this navigation breaks down — assistive technology may only recognize one of them, or it may present a confusing hierarchy of "main" landmarks to the user. - Standards compliance: Browsers and validators enforce the HTML specification's content model for
<main>. A nested<main>violates that content model and produces a validation error. - Semantic clarity: The
<main>element carries specific meaning. Nesting it dilutes that meaning and signals a structural misunderstanding of the document to both machines and other developers.
This issue commonly arises when composing pages from multiple templates or components — for example, when a layout template already wraps content in <main> and an inner component or partial also includes its own <main> element. It can also happen during refactoring when code is moved between files without checking the surrounding structure.
To fix the issue, identify the nested <main> element and replace it with a more appropriate element. If the inner content represents a thematic grouping, use <section>. If it represents a self-contained composition (like a blog post or comment), use <article>. If no particular semantic meaning is needed, a plain <div> works fine.
Examples
❌ Invalid: nested <main> elements
<main>
<h1>Welcome</h1>
<main>
<p>This nested main element is invalid.</p>
</main>
</main>
The inner <main> is a descendant of the outer <main>, which violates the content model.
✅ Fixed: inner <main> replaced with <section>
<main>
<h1>Welcome</h1>
<section>
<h2>Introduction</h2>
<p>This section is valid inside main.</p>
</section>
</main>
❌ Invalid: deeply nested <main> inside other elements
The nesting doesn't have to be direct. A <main> anywhere inside another <main> triggers this error:
<main>
<h1>Dashboard</h1>
<div class="content-wrapper">
<article>
<main>
<p>Still invalid, even though it's nested several levels deep.</p>
</main>
</article>
</div>
</main>
✅ Fixed: replaced with <div>
<main>
<h1>Dashboard</h1>
<div class="content-wrapper">
<article>
<div>
<p>Now valid with a neutral container element.</p>
</div>
</article>
</div>
</main>
❌ Invalid: component templates each providing <main>
This pattern often appears in frameworks where a layout and a page component both define <main>:
<!-- Layout template wraps page content -->
<main>
<!-- Page component output -->
<main>
<h1>About Us</h1>
<p>Our story begins...</p>
</main>
</main>
✅ Fixed: <main> only in the layout
<!-- Layout template wraps page content -->
<main>
<!-- Page component output -->
<h1>About Us</h1>
<p>Our story begins...</p>
</main>
Keep <main> at whichever level makes the most sense for your architecture — typically the outermost layout — and remove it from inner components. If you need to group the inner content, use <section>, <article>, or <div> instead.
The <main> element serves a specific structural role: it identifies the primary content of the page, distinct from repeated elements like headers, footers, and navigation. Because of this unique purpose, the HTML specification strictly limits where <main> can appear in the document tree. Nesting <main> inside a <section> element violates these rules because <section> represents a thematic grouping of content — placing <main> inside it implies that the dominant page content is merely a subsection of something else, which is semantically contradictory.
According to the WHATWG HTML living standard, a hierarchically correct <main> element is one whose ancestor elements are limited to <html>, <body>, <div>, <form> (without an accessible name), and autonomous custom elements. This means <main> cannot be a descendant of <article>, <aside>, <footer>, <header>, <nav>, or <section>.
Why this matters
- Accessibility: Screen readers and assistive technologies use the
<main>element as a landmark to let users skip directly to the primary content. When<main>is incorrectly nested inside<section>, assistive technologies may misinterpret the document structure, making navigation harder for users who rely on landmarks. - Standards compliance: Browsers are lenient and will render the page regardless, but the semantic meaning is broken. Future browser features or tools that depend on correct document structure may not work as expected.
- Document structure clarity: The
<main>element should clearly sit at the top level of your content hierarchy, making it immediately obvious to both developers and machines which part of the page is the primary content.
Additional rules for <main>
Beyond the ancestor restriction, remember that a document must not have more than one visible <main> element. If you use multiple <main> elements (for example, in a single-page application), all but one must have the hidden attribute specified.
Examples
Incorrect: <main> nested inside <section>
This structure places <main> as a descendant of <section>, which triggers the validation error:
<body>
<header>
<h1>My Website</h1>
</header>
<section>
<main>
<h2>Welcome</h2>
<p>This is the primary content of the page.</p>
</main>
</section>
</body>
Correct: <main> as a sibling of <section>
Move <main> out of the <section> so it is a direct child of <body>:
<body>
<header>
<h1>My Website</h1>
</header>
<main>
<h2>Welcome</h2>
<p>This is the primary content of the page.</p>
</main>
<section>
<h2>Related Topics</h2>
<p>Additional thematic content goes here.</p>
</section>
</body>
Correct: <section> elements inside <main>
If your primary content is divided into thematic sections, nest the <section> elements inside <main> — not the other way around:
<body>
<header>
<h1>My Website</h1>
</header>
<main>
<section>
<h2>Introduction</h2>
<p>An overview of the topic.</p>
</section>
<section>
<h2>Details</h2>
<p>A deeper dive into the subject.</p>
</section>
</main>
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
Correct: <main> wrapped in a <div>
If your layout requires a wrapper element around <main>, a <div> is a valid ancestor:
<body>
<div class="layout-wrapper">
<header>
<h1>My Website</h1>
</header>
<main>
<h2>Welcome</h2>
<p>This is the primary content of the page.</p>
</main>
</div>
</body>
The key principle is simple: <main> defines the dominant content of the entire document, so it belongs at the top level of your content hierarchy. Sectioning elements like <section>, <article>, <aside>, <nav>, <header>, and <footer> should never wrap <main> — instead, they should be placed as children or siblings of it.
The ARIA specification defines a set of roles that convey the purpose of an element to assistive technologies like screen readers. Many HTML elements have implicit ARIA roles — built-in semantics that map directly to ARIA roles without any extra markup. The <main> element is one of these: it automatically communicates the main landmark role to assistive technologies.
When you write <main role="main">, you're explicitly stating something the browser and assistive technologies already know. The W3C validator warns about this redundancy because it can signal a misunderstanding of how native HTML semantics work. While it won't break anything, unnecessary attributes add noise to your markup and can make code harder to maintain.
This principle applies broadly across HTML. For example, <nav> implicitly has role="navigation", <header> implicitly has role="banner" (when not nested inside a sectioning element), and <button> implicitly has role="button". Explicitly restating these roles is discouraged by both the W3C and the ARIA in HTML specification, which states: "Setting an ARIA role and/or aria-* attribute that matches the implicit ARIA semantics is unnecessary and is NOT RECOMMENDED."
Why this matters
- Code clarity: Redundant attributes make your HTML harder to read and can confuse other developers into thinking the attribute is necessary.
- Standards compliance: The W3C validator raises a warning, which can obscure more important issues in your validation reports.
- Best practices: Following the principle of using native HTML semantics without redundant ARIA keeps your code clean and aligns with the first rule of ARIA: "If you can use a native HTML element with the semantics and behavior you require already built in, do so, instead of re-purposing an element and adding an ARIA role."
How to fix it
Remove the role="main" attribute from any <main> element. The semantic meaning is already provided by the element itself.
If you're working with a <div> or another generic element that needs the main landmark role (for example, in a legacy codebase that cannot use <main>), then role="main" is appropriate and necessary on that element.
Examples
❌ Redundant role on <main>
<main role="main">
<h1>Welcome to my site</h1>
<p>This is the primary content of the page.</p>
</main>
The role="main" attribute is unnecessary here because <main> already implies it.
✅ Using <main> without a redundant role
<main>
<h1>Welcome to my site</h1>
<p>This is the primary content of the page.</p>
</main>
✅ Using role="main" on a non-semantic element (when necessary)
<div role="main">
<h1>Welcome to my site</h1>
<p>This is the primary content of the page.</p>
</div>
This approach is valid when you cannot use the <main> element — for instance, due to framework constraints or legacy browser support requirements. In most modern projects, prefer the <main> element instead.
The <marquee> element is obsolete, so text that scrolls across the page has to be animated with CSS instead.
Browsers still render <marquee> so old pages keep working, but the HTML standard lists it among the presentational features authors must not use, and points to CSS transitions and animations as the right tool for moving content. Its attributes, such as behavior, direction, scrollamount and scrolldelay, go away with it. The validator reports the element once and doesn't flag each of those attributes on its own.
Scrolling text is also hard to read, and a <marquee> gives visitors no way to stop it. WCAG success criterion 2.2.2 (Pause, Stop, Hide) asks for a way to pause, stop or hide content that moves by itself for more than five seconds alongside other content. Often the best fix is a plain, static line of text. If the movement has to stay, a CSS @keyframes animation reproduces it, and the prefers-reduced-motion media query turns it off for people who have asked their system to reduce motion. Pausing on hover helps mouse users, but keyboard and touch users still need a pause button to meet 2.2.2.
Invalid example
A news line that scrolls from right to left:
<marquee behavior="scroll" direction="left" scrollamount="4">
Registration for the spring semester closes on Friday.
</marquee>
Valid example
The same line scrolls with a CSS animation that pauses on hover and stops when the user prefers reduced motion:
<p class="ticker">
<span>Registration for the spring semester closes on Friday.</span>
</p>
.ticker {
overflow: hidden;
white-space: nowrap;
}
.ticker span {
display: inline-block;
padding-left: 100%;
animation: ticker 15s linear infinite;
}
.ticker:hover span {
animation-play-state: paused;
}
@keyframes ticker {
to {
transform: translateX(-100%);
}
}
@media (prefers-reduced-motion: reduce) {
.ticker span {
padding-left: 0;
animation: none;
}
}
The name attribute on the <a> element is obsolete in HTML5 and must be replaced with the id attribute.
Older versions of HTML used <a name="section1"> to create anchor targets within a page. HTML5 dropped this approach. The id attribute on any element now serves the same purpose, and it works on <a> tags as well as <div>, <section>, <h2>, or any other element. Fragment links like href="#section1" will scroll to whatever element has id="section1", regardless of element type.
The name attribute is still valid on elements like <input>, <form>, <meta>, and <map>, where it has a distinct function. On <a>, though, it has no valid use in modern HTML.
Invalid example
<a name="about">About us</a>
<p>Read more in our <a href="#about">about section</a>.</p>
Valid example
<h2 id="about">About us</h2>
<p>Read more in our <a href="#about">about section</a>.</p>
If the anchor wraps content that has no better semantic element, a <span> or <div> with an id works fine:
<span id="about">About us</span>
The name attribute is not a valid attribute for the <b> element in HTML.
<b> only takes the global attributes, and name is not one of them. HTML defines name on a handful of elements, mostly form controls, <form>, <iframe> and <meta>. The validator reports it twice on <b>: this warning, and an error saying that the attribute is not allowed on b at this point. Removing the attribute clears both.
name on <b> is often left over from an old anchor pattern. <a name="..."> used to mark a spot that links could jump to, and people copied the attribute onto other elements. It doesn't work there. To resolve a fragment such as #shipping, browsers look for an element with that id, and the only name they check is the one on <a>. So a link to #shipping won't scroll to <b name="shipping">.
Change name to id and the link works, as long as the value is unique on the page. If the value is only there for scripts, put it in a data-* attribute such as data-name, and update any script that finds the element with document.getElementsByName() to use getElementById() or a [data-name] selector.
Invalid example
<p><a href="#shipping">Shipping costs</a></p>
<p><b name="shipping">Shipping</b> is free on orders over 50 euros.</p>
Valid example
<p><a href="#shipping">Shipping costs</a></p>
<p><b id="shipping">Shipping</b> is free on orders over 50 euros.</p>
The name attribute is not a valid attribute for the <div> element.
The name attribute is only allowed on specific HTML elements that have a defined use for it, such as <input>, <form>, <iframe>, <object>, <map>, <select>, <textarea>, and <meta>. On these elements, name serves a purpose: identifying form data sent to a server, targeting frames, or referencing image maps.
The <div> element does not accept name. If the goal is to identify or reference a <div>, use the id attribute instead. The id attribute is a global attribute, valid on any HTML element, and provides a unique identifier for styling with CSS, targeting with JavaScript, or linking with fragment URLs.
If the name attribute was being used as a hook for document.getElementsByName(), switching to id with document.getElementById() (or using a class with document.querySelectorAll()) is the correct approach.
Invalid example
<div name="sidebar">
<p>Some content</p>
</div>
Valid example
<div id="sidebar">
<p>Some content</p>
</div>
The validator warns about name on a <frame> because the <frame> element itself is obsolete, and the warning goes away when the frame becomes an <iframe>, which accepts name.
In a frameset, name gives a frame the target name that other documents use to load pages into it. A link with target="content" opens its page in the frame named content, a form with the same target shows its response there, and a script can reach the frame through window.frames["content"]. Menus built with frames depend on it: every link in the menu frame points at the frame that holds the content. Browsers still honor these names, which is why the frames keep working.
The validator checks name on every element against a short list of elements that define it: button, details, fieldset, form, iframe, input, map, meta, object, output, select, slot and textarea. <frame> isn't on that list because it's obsolete. The validator reports this check as an informational message rather than an error, so it shows up as a warning, once for each named frame. The errors come from the elements themselves: each <frame> gets a message saying it's obsolete, and so does the <frameset> around it. Other attributes common on old frames, such as frameborder, scrolling and noresize, get no message on a <frame>.
Deleting name silences the warning but breaks every link and form that targets the frame, and the obsolete errors stay. Replace the frameset instead. A frame whose content moves into the page itself, such as a menu, no longer needs a name, since nothing loads into it. A frame that becomes an <iframe> keeps its name, so links with a matching target keep loading into it.
Invalid example
The links in menu.html use target="content" to open each recipe in the second frame:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Recipe box</title>
</head>
<frameset cols="200,*">
<frame src="menu.html" name="menu">
<frame src="welcome.html" name="content">
</frameset>
</html>
Valid example
The menu moves into the page, and the iframe keeps the name content, so the links still load into it:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Recipe box</title>
</head>
<body>
<nav>
<a href="soups.html" target="content">Soups</a>
<a href="desserts.html" target="content">Desserts</a>
</nav>
<iframe src="welcome.html" name="content" title="Recipe"></iframe>
</body>
</html>
The name attribute on the <img> element is obsolete in HTML5 and must be replaced with the id attribute.
Older pages used <img name="logo"> so scripts could reach the image through document.images["logo"], a pattern common in pre-DOM rollover scripts. HTML5 dropped the attribute. An id serves the same purpose: document.getElementById("logo") finds the image, and document.images also indexes images by their id.
The name attribute is still valid on elements like <input>, <form>, <meta>, and <map>, where it has a distinct function. On <img>, though, it has no valid use in modern HTML.
Invalid example
<img src="logo.png" name="logo" alt="Acme logo">
Valid example
<img src="logo.png" id="logo" alt="Acme logo">
Any script that referenced the image as document.images["logo"] keeps working with the id in place, or can switch to document.getElementById("logo").
A <meta> tag has stray quote characters right after its name, as in <meta"" name="description">, so the parser reads them as part of the element name.
In a start tag, the element name runs until the first space, / or >. With no space between meta and the quotes, the browser creates an unknown element called meta"" instead of a <meta> element. The name attribute isn't allowed on that unknown element, which is what this warning reports. Single quotes (<meta'') or a different number of quotes give the same message.
The warning is the mildest part of the problem. Because there is no real <meta> element, the description, viewport or other metadata in the tag never takes effect, and search engines don't see it either. The unknown element also ends the <head> early, and since it has no end tag, it wraps the rest of the page. Expect several errors on the same line in the report, including one that calls meta"" a completely unknown element and a "Stray end tag" error for head.
Remove the quotes so that a space follows meta. If a template or CMS writes the tag, fix it there: the quotes can come from an empty variable or attribute printed right after the tag name. Correcting the tag also clears the other errors it caused.
Invalid example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My page</title>
<meta"" name="description" content="A short summary of the page.">
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
Valid example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My page</title>
<meta name="description" content="A short summary of the page.">
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
The name attribute is reported on the <param> element because <param> itself is obsolete in the HTML standard.
<param> used to sit inside <object> to pass named values to plugins such as Flash, Java applets, or ActiveX controls. Each one carried a name and a value. Browsers dropped plugin support, the element was removed from the HTML specification, and the Nu validator now rejects its attributes, including name.
There is no replacement attribute to add. The fix is to delete the <param> element. If the surrounding <object> points at a resource that browsers still handle on their own, like an image or a PDF, set the data and type attributes directly on <object> and drop the parameters. If the content depended on a plugin, use a native element such as <video>, <audio>, or <iframe> instead.
Invalid example
<object data="movie.swf" type="application/x-shockwave-flash">
<param name="autoplay" value="true">
</object>
Valid example
<video src="movie.mp4" autoplay controls></video>
The name attribute is not a valid attribute for the <span> element in HTML.
The name attribute exists on specific elements like <a>, <form>, <input>, <map>, <meta>, <iframe>, <object>, and <param>. It was never part of the <span> element's specification. In older HTML practices, <a name="section"> was used to create anchor targets within a page, and some developers incorrectly applied the same pattern to <span> elements.
To create an anchor target on a <span> or any other element, use the id attribute instead. The id attribute is a global attribute, valid on every HTML element, and works as a fragment identifier in URLs (e.g., page.html#section-name).
If the name attribute was being used for JavaScript targeting or styling, switch to id, class, or data-* attributes depending on the use case.
Invalid example
<span name="intro">Welcome to the site.</span>
Valid examples
Use id to create a linkable anchor target:
<span id="intro">Welcome to the site.</span>
Use class when multiple elements share the same label:
<span class="intro">Welcome to the site.</span>
Use a data-* attribute for custom metadata consumed by JavaScript:
<span data-name="intro">Welcome to the site.</span>
The name attribute is not a valid attribute for the <table> element in HTML.
The name attribute was never part of any HTML specification for tables. Some older browsers tolerated it as a way to create anchor targets, but validators reject it because it does not belong on <table>. If the goal is to link directly to a table, use the id attribute instead. The id attribute is a global attribute, valid on any HTML element, and works as a fragment identifier in URLs (e.g., page.html#prices).
If the name attribute was being used for JavaScript access, switch to id and use document.getElementById(), or use a data-* attribute for storing custom metadata.
Invalid example
<table name="prices">
<tr>
<td>Item</td>
<td>Price</td>
</tr>
</table>
Valid example
Using id as a fragment target:
<table id="prices">
<tr>
<td>Item</td>
<td>Price</td>
</tr>
</table>
If custom metadata is needed rather than a link target, a data-* attribute works:
<table data-name="prices">
<tr>
<td>Item</td>
<td>Price</td>
</tr>
</table>
The name attribute is not a valid attribute for the <td> element in HTML.
The name attribute was never part of any HTML specification for table cells. Some older browsers tolerated it as a way to create anchor targets within a table, but validators reject it because it does not belong on <td>. If the goal is to create a link target so users can jump to a specific cell, use the id attribute instead. The id attribute is a global attribute, valid on any HTML element, and works as a fragment identifier in URLs (e.g., page.html#cell1).
If the name attribute was being used for JavaScript access, switch to id and use document.getElementById(), or use a data-* attribute for storing custom metadata.
Invalid example
<table>
<tr>
<td name="cell1">Data</td>
</tr>
</table>
Valid example
Using id as a fragment target:
<table>
<tr>
<td id="cell1">Data</td>
</tr>
</table>
If custom metadata is needed rather than a link target, a data-* attribute works:
<table>
<tr>
<td data-name="cell1">Data</td>
</tr>
</table>
The name attribute is not a valid attribute for the <th> element in HTML.
No HTML specification has defined name on header cells, so it has no effect on how the table renders or how assistive technology reads it. The validator reports it twice: this warning, and an error saying that the attribute is not allowed on th at this point. Both go away once the attribute is removed.
What to use instead depends on what the name was meant to do. To identify a header cell, give it an id. An id works as a link target (page.html#year), and data cells can point to it through their headers attribute. To mark a header as labeling its column or row, add scope="col" or scope="row". To keep a value that only scripts read, move it to a data-* attribute such as data-name.
Scripts that look these cells up with document.getElementsByName() still find them while the attribute is there, so update them to getElementById() or a [data-name] selector when you change the markup.
Invalid example
<table>
<tr>
<th name="year">Year</th>
<th name="revenue">Revenue</th>
</tr>
<tr>
<td>2024</td>
<td>1,200</td>
</tr>
</table>
Valid example
Using id and scope on the header cells, with headers on the data cells:
<table>
<tr>
<th id="year" scope="col">Year</th>
<th id="revenue" scope="col">Revenue</th>
</tr>
<tr>
<td headers="year">2024</td>
<td headers="revenue">1,200</td>
</tr>
</table>
If the value is only metadata for scripts, a data-* attribute works:
<table>
<tr>
<th data-name="year">Year</th>
<th data-name="revenue">Revenue</th>
</tr>
<tr>
<td>2024</td>
<td>1,200</td>
</tr>
</table>
A Vue template left in the page's HTML puts a name attribute on <transition-group>, and the validator warns because name only has a meaning on a short list of HTML elements.
Vue's <TransitionGroup> component animates items as they are added to or removed from a list. Its name prop sets the prefix of the CSS classes Vue applies during the animation, so name="fade" gives you fade-enter-active, fade-leave-to and so on. When Vue mounts onto markup that is already in the page (an in-DOM template, common when Vue is loaded from a CDN without a build step), the browser parses that markup first, and the validator checks it before Vue has compiled anything.
To an HTML parser, transition-group is an autonomous custom element, because its name contains a hyphen. HTML lets custom elements carry any attribute without a namespace, which is why this is a warning and not an error. The validator still reports name on every element outside the ones where HTML defines it: button, details, fieldset, form, iframe, input, map, meta, object, output, select, slot and textarea.
To clear the warning, keep Vue's template syntax out of the HTML the validator checks. With a build step, write the component as a single-file component (.vue), so the page only contains the rendered output. Without one, move the template into a <script type="text/x-template"> element and point the app's template option at its id. The validator doesn't check markup inside a script element, and Vue compiles the template the same way.
Because HTML permits the attribute on custom elements, keeping the in-DOM template and muting this warning in your reports is also a reasonable choice.
Invalid example
<div id="app">
<transition-group name="fade" tag="div">
<p>New message</p>
</transition-group>
</div>
Valid example
<div id="app"></div>
<script type="text/x-template" id="app-template">
<transition-group name="fade" tag="div">
<p>New message</p>
</transition-group>
</script>
<script>
Vue.createApp({ template: "#app-template" }).mount("#app");
</script>
The validator warns about a name attribute on a custom element, any element whose name contains a hyphen, because it only expects name on a short list of built-in HTML elements.
The validator checks name against a fixed list: button, details, fieldset, form, iframe, input, map, meta, object, output, select, slot and textarea. It makes no exception for custom elements. HTML itself is more permissive here: an autonomous custom element may carry any attribute without a namespace that its author gives a meaning to, which is why the message is a warning and not an error.
The attribute usually comes from a Web Component that reads data such as a person's name from name, or from a framework component written straight into the page's HTML, such as a Vue component in an in-DOM template. In the second case the browser parses the markup before the framework compiles it, so a name prop reaches the validator as a plain attribute.
One kind of custom element does use name the way HTML defines it. A form-associated custom element, whose class sets static formAssociated = true and reports its value through ElementInternals, takes part in forms like an input does, and the HTML standard lists name as its attribute for form submission and the form's elements API. The validator doesn't run your scripts, so it can't tell such an element apart from any other. If the element is form-associated, keep name and mute the warning in your reports.
For any other custom element, rename the attribute to one that HTML doesn't reserve, such as person-name or data-name, and update the code that reads it: the getAttribute() calls and observedAttributes list of a Web Component, or the prop declaration of a framework component.
Invalid example
<profile-card name="Ada Lovelace" job-title="Mathematician"></profile-card>
<script>
customElements.define("profile-card", class extends HTMLElement {
connectedCallback() {
this.textContent = this.getAttribute("name") + ", " + this.getAttribute("job-title");
}
});
</script>
Valid example
<profile-card person-name="Ada Lovelace" job-title="Mathematician"></profile-card>
<script>
customElements.define("profile-card", class extends HTMLElement {
connectedCallback() {
this.textContent = this.getAttribute("person-name") + ", " + this.getAttribute("job-title");
}
});
</script>
Before HTML5, the way to create a link target within a page was to use a "named anchor" — an <a> element with a name attribute. This allowed other links to jump to that specific spot using a fragment identifier (e.g., href="#section-5"). In HTML5, the name attribute on <a> elements has been marked as obsolete. Instead, the id attribute on any element serves this purpose, making the extra <a> wrapper unnecessary.
This matters for several reasons:
- Standards compliance: Using obsolete attributes means your markup doesn't conform to the current HTML specification, which can cause W3C validation errors.
- Cleaner markup: Named anchors add an extra element that serves no semantic purpose. Using
iddirectly on the target element is simpler and more meaningful. - Accessibility: Screen readers and assistive technologies work better with semantic HTML. An
idon a heading or<section>provides clearer document structure than a nested anchor element. - Browser behavior: While browsers still support
namefor backward compatibility, relying on obsolete features is risky as future browser versions may change or drop support.
To fix this, remove the <a name="..."> element and place an id attribute directly on the nearest appropriate container element, such as a heading (<h2>, <h3>, etc.), a <section>, or a <div>.
Examples
Incorrect: using the obsolete name attribute
<h2>
<a name="section-5">Section 5</a>
</h2>
The <a> element here exists solely to create a link target, adding unnecessary markup.
Correct: using id on the heading
<h2 id="section-5">Section 5</h2>
The id attribute on the <h2> makes it a valid fragment link target without any extra elements.
Linking to the section
Both approaches allow navigation via the same fragment URL. The link syntax doesn't change:
<a href="#section-5">Jump to Section 5</a>
Using id on other container elements
The id attribute works on any HTML element, so you can place it wherever makes the most sense semantically:
<section id="contact-info">
<h2>Contact Information</h2>
<p>Email us at hello@example.com.</p>
</section>
Incorrect: multiple named anchors in a document
<p>
<a name="intro">Welcome to our page.</a>
</p>
<p>
<a name="conclusion">Thanks for reading.</a>
</p>
Correct: replacing all named anchors with id attributes
<p id="intro">Welcome to our page.</p>
<p id="conclusion">Thanks for reading.</p>
Remember that id values must be unique within a document — no two elements can share the same id. If you're migrating from name attributes, check for duplicates and ensure each id is used only once.
The name attribute on <a> elements is obsolete in HTML5 and should be replaced with the id attribute.
In older versions of HTML, the name attribute on anchor elements was used to create fragment identifiers — targets you could link to with #section-name in a URL. In HTML5, this approach has been deprecated in favor of the id attribute, which can be placed on any element, not just <a> tags.
Using id is more flexible because you can turn any element into a link target directly, without wrapping it in an anchor. The id attribute works the same way for fragment navigation: a link pointing to #section-name will scroll to the element with id="section-name".
HTML Examples
❌ Obsolete usage with name
<a name="about"></a>
<h2>About Us</h2>
<p>Welcome to our site.</p>
<a href="#about">Go to About</a>
✅ Fixed using id
<h2 id="about">About Us</h2>
<p>Welcome to our site.</p>
<a href="#about">Go to About</a>
The id attribute is placed directly on the <h2> heading, eliminating the need for an empty <a> tag entirely. The #about link works exactly the same way.
The name attribute was historically used on img elements to reference images through JavaScript's document.images collection or via document.getElementsByName(). In early HTML, name served as an identifier for various elements before the id attribute was widely adopted. The HTML living standard (WHATWG) now marks name as obsolete on img elements, meaning it should no longer be used in new content.
This matters for several reasons:
- Standards compliance: Using obsolete attributes means your HTML does not conform to the current specification, which can cause validation errors and may lead to unexpected behavior in future browser versions.
- Consistency: The
idattribute is the universal mechanism for uniquely identifying any HTML element. Usingidinstead ofnamekeeps your markup consistent and predictable. - JavaScript and CSS targeting: Modern APIs like
document.getElementById()anddocument.querySelector()work withid, notnameon image elements. CSS selectors also target elements byid(e.g.,#myImage), makingidthe more versatile choice. - Fragment linking: The
idattribute allows you to link directly to an element using a URL fragment (e.g.,page.html#myImage), whereas the obsoletenameattribute onimgdoes not serve this purpose.
To fix this issue, simply replace name with id on your img elements. Keep in mind that id values must be unique within the entire document — no two elements can share the same id. If you have JavaScript code that references the image by name (e.g., document.images["myImage"] or document.getElementsByName("myImage")), update those references to use document.getElementById("myImage") or document.querySelector("#myImage") instead.
Examples
Incorrect: using the obsolete name attribute
<img src="photo.jpg" name="heroImage" alt="A sunset over the ocean">
This triggers the validation error because name is no longer a valid attribute on img.
Correct: using the id attribute
<img src="photo.jpg" id="heroImage" alt="A sunset over the ocean">
The name attribute is replaced with id, and the element can now be targeted with document.getElementById("heroImage") or the CSS selector #heroImage.
Updating JavaScript references
If your existing code references the image by name, update it accordingly.
Before (relying on name):
<img src="logo.png" name="siteLogo" alt="Company logo">
<script>
var logo = document.images["siteLogo"];
logo.style.border = "2px solid blue";
</script>
After (using id):
<img src="logo.png" id="siteLogo" alt="Company logo">
<script>
var logo = document.getElementById("siteLogo");
logo.style.border = "2px solid blue";
</script>
Multiple images that previously shared a name
Since id values must be unique, you cannot give the same id to multiple elements. If you previously used the same name on several images and selected them as a group, switch to a shared class instead:
<img src="slide1.jpg" class="gallery-image" alt="Mountain landscape">
<img src="slide2.jpg" class="gallery-image" alt="Forest trail">
<img src="slide3.jpg" class="gallery-image" alt="River valley">
<script>
var images = document.querySelectorAll(".gallery-image");
images.forEach(function(img) {
img.style.borderRadius = "8px";
});
</script>
This approach is standards-compliant and gives you flexible, modern element selection using class for groups and id for unique elements.
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