Can an id attributes value start with a number?
-
why dont u try it urself? what are the results.sushil bharwani– sushil bharwani2010-11-03 04:59:28 +00:00Commented Nov 3, 2010 at 4:59
-
I was going to post a snarky comment about just writing a basic HTML/XHTML page and validating it yourself on W3C, but then I realised that not everyone knows about the W3C validator. So heres a link :) validator.w3.orgDarko– Darko2010-11-03 05:06:06 +00:00Commented Nov 3, 2010 at 5:06
2 Answers
For HTML, no - http://www.w3.org/TR/html401/types.html#type-name
Theoretically, the collection of legal values in XHTML could be much larger however I doubt it would be compatible with many browsers. See http://www.w3.org/TR/xhtml1/#C_8
Comments
The currently accepted answer is actually incorrect.
All browsers have always supported ID attributes that start with a number, and HTML5 now allows it. See http://mathiasbynens.be/notes/html5-id-class:
The HTML 4.01 spec states that
IDtokens 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 (.). For theclassattribute, there is no such limitation. Classnames can contain any character, and they don’t have to start with a letter to be valid.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.
Note that you will need to escape the ID attribute value correctly if you want to use it in CSS or JavaScript. See http://mothereffingcssescapes.com/#123-foo.
4 Comments
-moz / -webkit CSS prefixes).