I know that in HTML4 classes and id cannot start with numbers.
I am coding in HTML 5/php and alot of my ids and classes have just numbers in them that point to a primary key in my database for jquery ajax calls.
I cannot find the documentation for HTML5 classes and id spec. Is it valid in HTML 5 to have class and id names such as,
class="122"
id="13213"
I have ran my output code through w3c conformance checker and all is good, but still I would like confirmation!?
Thanks
I’ve researched this thoroughly and wrote about my findings: The id attribute got more classy in HTML5. From that article:
HTML5 gets rid of the additional restrictions on the
idattribute. 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.
To target a classname or ID that starts with a digit in CSS or in JavaScript using the Selectors API, you should escape them. For example, to target the element with id="404", you can’t just use #404 — you’d have to escape it as follows:
#\34 04 {
background: pink;
}
The official html5 specs are here: id-attribute in html5.
(Here you go for html4)
So in html5 the only restriction is minimum 1 char and no whitespaces.
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