The id attribute

id sets a unique identifier for an element within the whole document — used by CSS, JavaScript, anchor links (#id), and label.

Applies to

global

Values

Any string with no spaces (the modern spec allows almost any character except spaces).

Example

<h2 id="pricing">Pricing</h2>
<a href="#pricing">Jump to pricing</a>

Edge cases

  • id must be unique across the whole page — duplicates break #anchor behavior, label for, and querySelector('#...').
  • An id starting with a digit is technically valid in HTML5 but can cause issues in CSS selectors without escaping.

Accessibility

  • id is the foundation for label for, aria-labelledby, and aria-describedby.

Related tools