W3C home > Mailing lists > Public > www-html@w3.org > November 2013

Re: ID/Class Names beginning with numbers

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Wed, 27 Nov 2013 19:28:38 +0200
Message-ID: <52962BC6.9050401@cs.tut.fi>
To: Thomas BAYER - Web Alliance <thomas-bayer@web-alliance.fr>, "'www-html@w3.org'" <www-html@w3.org>
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.


> 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.

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

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:06:26 UTC