id attribute values should be unique

Deprecated: every id value on a page should be unique. WCAG 2.2 made criterion 4.1.1 obsolete, so this is now good practice; duplicate-id-aria covers the ids that affect accessibility.

Deprecated

Rule IDduplicate-id
ImpactMinor
Success criterion 4.1.1 Parsing · A
Readabler fix Needs a change in the website’s code

Example

Before
<section id="reviews">
  <h2>Customer reviews</h2>
</section>
<div id="reviews" class="reviews-widget"></div>

A "Jump to reviews" link may land on the wrong element; a script may fill the wrong box.

After
<section id="reviews">
  <h2>Customer reviews</h2>
</section>
<div id="reviews-widget" class="reviews-widget"></div>

The link and the script each reach the intended element.

Why it matters

Browsers tolerate repeated ids, but getElementById, href="#reviews" and :target styles only ever find the first one. In-page links then send keyboard and screen reader users to the wrong spot, and scripts may update the wrong part of the page without any visible error.

This rule tested parsing under WCAG success criterion 4.1.1, which WCAG 2.2 removed as obsolete. The check is deprecated and off by default, and a duplicate here does not on its own fail WCAG. When a duplicate id is used by a label or an ARIA attribute, it does affect users, and duplicate-id-aria reports it.

How to fix it

Give each element its own id and update anything that refers to it.

Find the duplicates. Run this in the browser console:

<script>
  const ids = [...document.querySelectorAll("[id]")].map((e) => e.id);
  console.log(ids.filter((id, i) => ids.indexOf(id) !== i));
</script>

Rename with meaning. Say what each element is, not just a number:

<section id="reviews">…</section>
<div id="reviews-widget">…</div>

Use classes for repeated styling. An id is not needed to style a group of elements:

<div class="product-card">…</div>
<div class="product-card">…</div>

Third-party embeds. Widgets pasted twice (a newsletter form in the header and footer) often repeat their ids. Use the embed's option for a custom id, or load it once.

Templates. Generate ids per instance in loops and components instead of copying a fixed string.

Checklist

  1. List duplicate ids with a console query.
  2. Rename each copy with a descriptive id.
  3. Use classes instead of ids for repeated styling.
  4. Check embedded widgets that appear twice.

How the check works

The check covers elements with an id that are neither focusable nor referenced by a label or ARIA attribute (those have their own checks). It fails when the same id value appears more than once in the same document or shadow root. It is deprecated and disabled by default, since WCAG 2.2 removed the parsing criterion.

Resources

Updated October 27, 2026