html id fields

2019-09-21

 | 

~1 min read

 | 

155 words

Ids are everywhere. But what are the rules for them?

Turns out, the rules in HTML5 are pretty permissive: unique, at least one character, and no spaces.1

From the spec itself:2

When specified on HTML elements , the id attribute value must be unique amongst all the IDs in the element’s tree and must contain at least one character. The value must not contain any ASCII whitespace.

The rules used to be more specific. In HTML43:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (”-”), underscores (”_”), colons (”:”), and periods (”.”).

Note the restrictions as well as the fact that the id had to start with a letter.

Footnotes



Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!