Web Foundations
By Adam Roberts

id (HTML attribute)

By Adam Roberts


The id attribute provides a unique identifier for an element within the document. It may be used by an a element to create a hyperlink to this particular element.

This identifier may also be used in CSS code as a hook that can be used for styling purposes, or by JavaScript code (via the Document Object Model, or DOM) to make changes or add behavior to the element by referencing its unique id.

Note that the id attribute cannot be applied to the following elements:

  • base
  • head
  • html
  • meta
  • script
  • style
  • title
<span id="thisspan">A uniquely identifiable element.</span>


The most important aspect of the id attribute is that it must be absolutely unique. Unlike the class attribute, which may apply the same value to many elements in a page, an id that’s applied to an element must not match an id used anywhere else on the same page.

The id attribute value must begin with a letter in the roman alphabet (a–z or A–Z); this can be followed by any combination of letters (a–z or A–Z), digits (0–9), hyphens (-), underscores (_), colons (:), and periods (.). The id value is case sensitive, thus <span id="me">This is me</span> and <span id="ME">This is me</a> would be considered to be separate and uniquely identifiable elements on the same web page.

  • This article comes a bit late. Most of these claims are no longer true in HTML5.1 and HTML as a Living Standard.

    • Paul P

      Hi, I just saw your comment. Can you point me to the specs of HMTL5.1 where it says that some claims of this article is no longer true? I want to learn the new or latest ones. Thanks

  • Desouki

    The title at head of the page is “Web FOUNDATIONS”, Alexander!