The MDN says:
Note: Using characters except ASCII letters and digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in
HTML 4. Though this restriction has been lifted in HTML 5, an ID
should start with a letter for compatibility.
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id
HTML 4.01 spec:
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 (".").
However, HTML5 spec and the WHATWG HTML Living Standard allows IDs start with digits:
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.
So I would suggest to stick to the MDN recommendation: For compatibility reasons, don't start your ID or name with a digit. Instead id="1"
, use something like id="img1"
.