Re: ID/Class Names beginning with numbers

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 
4 is still the "official" recommendation, but there has been no work on 
it for years.) And here HTML5 reflects browser practices.

In HTML5, an id attribute value may be any nonempty string that does not 
contain space characters. So id=42 is fine, and so is id=§42?. And a 
class attribute value may be literally any string, for example class="42 
¿Qué? #^!@§". Since it is by definition a sequence of class names 
separated by space characters, a class name cannot contain a space 
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=4foo and class=4foo work fine as 
far as HTML only is considered, they pose problems in CSS, and 
especially class attributes are mainly used for CSS purposes. HTML5 (or 
a browser) has no objection to class=4foo, but .4foo is not a valid 
selector in CSS; you would need to use escape notations as in .\34foo 
which is not that convenient and intuitively clear.

Yucca

Received on Wednesday, 27 November 2013 17:29:09 UTC