What HTML attribute is used to specify an element's unique identifier?

The story behind the answer

The HTML attribute used to specify an element’s unique identifier is id. Its value identifies a particular element within a document and can be targeted by CSS, JavaScript, hyperlinks, and accessibility tools.

For example, an element written as <section id="history"> can be linked directly with a URL ending in #history. CSS selects that element with #history, while JavaScript can retrieve it with methods such as getElementById(). The identifier is part of the element’s markup, not a separate HTML element.

The main source of confusion is class. A class groups multiple elements that share a role or styling, whereas an id is intended to identify one specific element in the document. The name attribute has specialized uses on certain elements, especially form controls, and value stores data associated with some controls; neither is the general-purpose unique-identifier attribute.

HTML authoring conventions require id values to be unique within a document. An id may contain letters, digits, and other permitted characters, but simple, descriptive values are easiest to maintain and link to.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: