--- obsoleteMessage: | This technique relates to 4.1.1: Parsing, which was removed as of WCAG 2.2. obsoleteSince: 22 ---

# Ensuring that `id` attributes are unique on a Web page

ID: H93

Technology: html

Type: Technique

## When to Use

All HTML pages

## Description

The objective of this technique is to avoid errors that result from the same `id` attribute being used multiple times on the same page. These errors can be avoided by making sure the page doesn't have duplicate `id` values. This can be done manually or by using HTML's mechanism to specify the technology and technology version, and validating the document for this condition. There are several validators that the developer can use; validation reports generally mention this type of error. The document type declaration is not strictly necessary for this type of evaluation, but specifying the document type declaration makes it easier to use a validator.

## Examples

### Duplicate id attributes in form elements

In this example, the first name and last name inputs both have an `id` attribute with the same value. Due to the way accessible names are computed, this results in the last name input having no accessible name.

    <label for="fname">First Name</label>
    <input autocomplete="given-name" id="fname" type="text">
    <label for="lname">Last Name</label>
    <input autocomplete="family-name" id="fname" type="text">

### HTML Validators

HTML pages include a document type declaration (sometimes referred to as !DOCTYPE statement). The developer can use offline or online validators (see Resources below) to check that `id` attribute values are only used once on a page. The W3C validator, for example, will report "Duplicate ID" when it encounters the subsequent uses of an `id` value.

## Tests

### Procedure

1. Check that all `id` attribute values are unique on the page.

### Expected Results

- Check #1 is true.

## Resources

- HTML - `id` attribute
- Nu HTML Checker
- Do not forget to add a doctype by the W3C Quality Assurance Initiative explains what doctypes are and why you should use them

For other resources, see G134: Validating Web pages.