</>
ValidateHTML

Duplicate ID Attributes

The id attribute must be unique within a page. When multiple elements share the same id, document.getElementById() only returns the first match. Anchor links (#section) may scroll to the wrong element. CSS ID selectors may not style all instances.

Find this error in your own code. Paste your HTML or enter a URL, free and instant.Open the validator
23.2%
of sites tested

How common is this error?

We ran this validator over the home page of the Tranco top 5,000 websites in August 2026. 617 of the 2,656 sites we could reach hit it. That makes it the 9th most common HTML problem we found, across 5,925 occurrences. See the full study.

Most frequent wording: Duplicate ID "porb"

Why It Matters

Duplicate IDs break JavaScript functionality, cause ARIA references to point to wrong elements (breaking screen reader navigation), make anchor links unreliable, and produce invalid HTML that validators flag as errors.

Common Causes

  • Reusing a component or template that hardcodes an id, then rendering it more than once on the same page.
  • Copy-pasting a block of markup without updating its id attributes.
  • Generating list items from data and applying the same id to every row.

Code Examples

Invalid
<div id="header">Site header</div>
<div id="header">Page header</div>

<label for="email">Email</label>
<input id="email" type="email">
<input id="email" type="text">
Valid
<div id="site-header">Site header</div>
<div id="page-header">Page header</div>

<label for="email">Email</label>
<input id="email" type="email">
<input id="username" type="text">

How to Fix

  • 1Search your HTML for duplicate IDs. Our validator flags them automatically.
  • 2Use more specific ID names (site-header vs page-header).
  • 3Use classes instead of IDs when styling multiple similar elements.
  • 4For JavaScript, use data-* attributes or classes instead of IDs when selecting multiple elements.

Frequently Asked Questions

Why does my JavaScript only affect the first element?
document.getElementById() returns only the first match for a given id. When two elements share an id, the second is unreachable by that method, so scripts and styles targeting it appear to do nothing.
Can two elements share an id if they are in different sections?
No. The id must be unique across the entire document, regardless of section or nesting. Use a class for repeated elements and reserve id for one-of-a-kind anchors.
How do duplicate IDs affect accessibility?
ARIA relationships (aria-labelledby, aria-describedby, label for) point to an id. If that id is duplicated, screen readers may associate the wrong element, breaking the accessible name or description.

Check Your HTML Now

Our validator detects this error automatically and shows the exact line number.

Open HTML Validator

Related HTML Errors

← View all HTML errors