As the title suggests, I am “afraid” to have elements with either id="12" or class="12".
I know the spec allows this, especially for HTML5, but are there any problems you encountered using this?
In this particular case I have <li> elements that contain months and I want to give them a class name with the month number (e.g. 1 for January) to reference them in JavaScript. And instead of class="1" I do class="mon-1".
Thanks.
If you’re using HTML4 or XHTML and want your documents to be valid, you cannot use a digit for the id. It will however probably work perfectly fine in most mainstream browsers, since they tend to not break your layout just because of a wrongly named id.
Problems more often occur due to : or . being inside an id name and trying to select those in JavaScript.
I would still advise against using only digits for the id, if you’re not using HTML5. Just because it adheres to standards. If you’re using mon-1 as the id, that wouldn’t be a problem either, it is allowed to contain digits, just not start with one.
If you want to use a class name of: .mon-1 that is perfectly fine anyways, because classes naming-restriction is to not contain a space.