According to the recommendation W3C of 28 October 2014, HTML5
A vocabulary and associated Apis for HTML and XHTML, is regulating:
3.2.5.1 The attribute id
The attribute id
specifies the unique identifier (ID) of its element.
The value must be exclusive among all IDs
in the initial tree
element and must contain at least one character. The value must not
contain space characters.
There are no other restrictions on the form that a ID
can assume, in particular, the IDs
may consist only of digits, starting with a
digit, start with an underscore, consist only of punctuation etc.
The unique identifier of an element can be used for a
variety of purposes, mainly as a way to link
specific parts of a document using identifiers of
fragments, as a way to direct an element when creating
scripts and as a way to style a specific element. CSS.
Identifiers are opaque strings. Particular meanings do not
shall be derived from the attribute value id
.
Which clearly confirms that you did not commit any violations in your HTML code, but taking a look at the documentation MDN on Ids there is a recommended note:
Note: Using characters other than letters and ASCII digits, '_', '-' and '.' can cause compatibility problems since they were not
allowed in HTML 4. Although this restriction is suspended in HTML 5,
an ID must start with a letter for compatibility purposes.
That recommendation that an ID must start with a letter for compatibility purposes is quite significant because according to the recommendations:
In the CSS, identifiers (including element names, classes and
Ids on selectors ) may contain only [a-za-Z0-9] characters and
ISO 10646 U + 00A0 and above, in addition to the hyphen (-) and the
underlining ( _); they cannot start with one digit, two hyphens or
a hyphen followed by a digit. Identifiers may also contain
escape characters and any ISO 10646 character as a code
numeric (see next item). For example, the identifier
"Q&A?" can be written as "B & W ?" or "B 26 W 3F".
Having as a consequence that its id
started by a number is compatible with the HTML5 but is not compatible with CSS and so is not recognized.
On the question of being bad practice using explicitly numerical identifiers yes I agree with the recommendation made in the comments of the question Is it bad practice to put numbers as id in HTML elements? If yes why?
@Augusto Vasquesso why can’t I use a number at the beginning of a
id
? Since there is no restriction. I have already checked numerous times if it was not a problem of lack of ; or { , or anything else. It just doesn’t work. If you know what’s going on help me, please :D. Thanks!– GiovanePS
It’s just compatibility anyway?
– GiovanePS
@Giovaneps look at the final part of my reply which deals specifically with CSS.
– Augusto Vasques