Why can’t I have a numeric value as the ID of an element?

That’s just what the spec says.

From the HTML 4 specification:

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 (“.”).

The good news is that the HTML 5 specification is more lenient:

The id attribute specifies its element’s unique identifier (ID).
The value must be unique amongst all the IDs in the element’s home
subtree and must contain at least one character. The value must not
contain any space characters.

Leave a Comment