HTML - Element's unique identifier (Id Attribute)

> (World Wide) Web - (W3|WWW) > HyperText markup Language (HTML)

1 - About

The DOM specification gives the concept of an element's unique identifier (ID)

An element's unique identifier can be used for a variety of purposes, most notably as a way to:

Advertising

3 - Syntax

It is non-conforming to have two id attributes with the same value. This will be hard to debug. Duplicate IDs lead to the wrong element being selected, with sometimes disastrous effects whose cause is hard to determine.

3.1 - HTML4

Tokens:

  • must be unique amongst all the IDs in the element's home subtree
  • must contain at least one character.
  • must not contain any space characters.
  • must begin with a letter ([A-Za-z])
  • may be followed by any number of letters, digits ([0-9]), hyphens (“-”), underscores (“_”), colons (“:”), and periods (“.”).

3.2 - HTML5

Tokens:

  • must be unique amongst all the IDs in the element's home subtree
  • must contain at least one character.
  • must not contain any space characters.

There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.

Advertising

3.3 - Management

3.3.1 - Select

4 - Documentation / Reference

web/html/id.txt · Last modified: 2019/03/16 21:22 by gerardnico