Re: ID/Class Names beginning with numbers

"Jukka K. Korpela" <[email protected]> Wed, 27 Nov 2013 19:28:38 +0200
Newsgroups gmane.comp.web.html.general
Message-ID <[email protected]>
2013-11-27 17:45, Thomas BAYER - Web Alliance wrote:

> I know my question may sound stupid or might have been answered tons of
> times, but here it is : why on earth can't a ID/Class name begin with a
> number ?

They can, in HTML5, which is what we mostly discuss on this list. (HTML=20
4 is still the "official" recommendation, but there has been no work on=20
it for years.) And here HTML5 reflects browser practices.

In HTML5, an id attribute value may be any nonempty string that does not=20
contain space characters. So id=3D42 is fine, and so is id=3D=A742?. And =
a=20
class attribute value may be literally any string, for example class=3D"4=
2=20
=BFQu=E9? #^!@=A7". Since it is by definition a sequence of class names=20
separated by space characters, a class name cannot contain a space=20
character, but other than this, a class name can be any string.

http://www.w3.org/TR/html5/dom.html#the-id-attribute
http://www.w3.org/TR/html5/dom.html#classes

> Wouldn't it be a huge enhancement for web developers if it was possible=
 ?

No, it's not a big deal. Although id=3D4foo and class=3D4foo work fine as=
=20
far as HTML only is considered, they pose problems in CSS, and=20
especially class attributes are mainly used for CSS purposes. HTML5 (or=20
a browser) has no objection to class=3D4foo, but .4foo is not a valid=20
selector in CSS; you would need to use escape notations as in .\34foo=20
which is not that convenient and intuitively clear.

Yucca