Recently had a debate on a question here where the user in the answer said that ID starts with a number is acceptable in HTML5, so is that true? I don't see any relevant documentation on this topic, also he provided me a link to this answer here, but seems like relevant link is no more.
So the question is, do HTML5 allow ids
to start with a number?
Now for sure this fails in CSS --
<div id="5hello">Fails Completely</div>
#5hello {
color: red;
}
Update: I am not even sure, that HTML5 allows the id's
to start with a number or not, it's just that declaring id
on an element is not enough, as HTML alone is not a question here, but does using <!DOCTYPE html>
enables other technologies like CSS and JavaScript to work with the id's starting with no.? Am sure CSS fails, not tested with JavaScript but am sure that will fail too.
According to this guy the answer is YES.
HTML5 gets rid of the additional restrictions on the id attribute. The only requirements left — apart from being unique in the document — are that the value must contain at least one character (can’t be empty), and that it can’t contain any space characters.
You should follow W3C documents regarding this question: link
3.2.3.1 The id attribute
The id attribute specifies its element's unique identifier (ID). [DOMCORE]
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.
An element's unique identifier can be used for a variety of purposes, most notably as a way to link to specific parts of a document using fragment identifiers, as a way to target an element when scripting, and as a way to style a specific element from CSS.
Identifiers are opaque strings. Particular meanings should not be derived from the value of the id attribute.
Edit 1: I really like this comment, so if the author does not mind I will add it to my answer.
“CSS fails” – no, you just have to do it right: link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With