---
title: Unique id Attribute Values | Accessibility Rule
description: id attribute value must be unique
source_url:
  html: https://testingbot.com/support/accessibility/web/rules/duplicate-id
  md: https://testingbot.com/support/accessibility/web/rules/duplicate-id/index.md
---
# Ensure every id attribute value is unique

Rule ID: duplicate-idUser Impact: minorGuidelines: Deprecated

Every `id` attribute on a page must be **unique**. This rule ensures no two elements share the same `id`, which is critical for accessibility and valid HTML.

## What is being tested?

The rule checks that each element using the `id` attribute has a unique value across the document.

## Why it matters

Duplicate IDs can break important features:

- Screen readers may only detect the first instance, skipping others.
- Form labels and table headers may stop working properly.
- JavaScript may only act on the first element with that ID, ignoring the rest.

## How to fix the problem

- Rename duplicate `id` values to ensure uniqueness.
- For repeated elements, use distinct IDs like `button-1`, `button-2`, etc.
- Check your HTML with the [W3C Markup Validator](https://validator.w3.org/) to spot duplicate IDs.

## Example code

**Incorrect example:** (duplicate id)

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

**Correct example:** (unique ids)

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

## Best practices

- Use IDs only when necessary, such as for form labels or ARIA attributes.
- Prefer `class` selectors for styling or JavaScript targeting when multiple elements are involved.
- Be consistent with ID naming to avoid confusion or future duplication.

## Important notes

- Duplicate IDs don’t just affect accessibility — they can also break JavaScript functionality.
- Even though WCAG 2.0 does not require valid HTML, valid markup helps prevent many accessibility issues.

## Other Rules

Interested in other web accessibility rules? Please see these other rules:

- [area-alt](https://testingbot.com/support/accessibility/web/rules/area-alt)
- [aria-allowed-attr](https://testingbot.com/support/accessibility/web/rules/aria-allowed-attr)
- [aria-braille-equivalent](https://testingbot.com/support/accessibility/web/rules/aria-braille-equivalent)
- [aria-command-name](https://testingbot.com/support/accessibility/web/rules/aria-command-name)
- [aria-conditional-attr](https://testingbot.com/support/accessibility/web/rules/aria-conditional-attr)
