[whatwg] Predefined classes are gone

Michel Fortin michel.fortin at michelf.com
Thu May 17 15:20:54 PDT 2007

Was this supposed to be on the list? I'm not sure, so I'll reply to  
you personally. Feel free to forward it if you want.

Le 2007-05-17 à 16:44, Adrienne Travis a écrit :

> The CSS 1 spec says that a selector CANNOT start with a dash. I find
> nothing in the CSS 2 spec to overwrite that, though i could be missing
> something.
> "in CSS1, selectors (element names, classes and IDs) can contain only
> the characters A-Z, 0-9, and Unicode characters 161-255, plus dash
> (-); they cannot start with a dash or a digit; they can also contain
> escaped characters and any Unicode character as a numeric code (see
> next item)."
> Again, hard to say if it's important to have backwards-compatibility
> or not, but that IS an issue.

Possibly not much of an issue however since browsers following the  
specification would have to handle it anyway, if they follow the  
normative grammar of the language.

With CSS 3, the grammar of the class selector is defined this way:

      : '.' IDENT

In other words: a dot followed by IDENT, with IDENT defined as:

      ident     [-]?{nmstart}{nmchar}*

Which is: an optional dash, a start character (alphabetic +  
underscore + extended unicode) followed by any character  
(alphanumeric + underscore + dash + extended unicode).

In other word, a class name may not begin with a number, but, per CSS  
3, it can begin with a dash. I found no other paragraph disallowing  
class name selectors starting with a dash.

-- CSS 3 grammar: http://www.w3.org/TR/2005/WD-css3- 

CSS 2.1 allows the leading dash just like CSS 3, but surprisingly  
does not allow any (non-escaped) underscore in a class name.

-- CSS 2.1 grammar: http://www.w3.org/TR/CSS21/grammar.html

CSS 2 grammar does not allow the leading dash.

-- CSS 2 grammar: http://www.w3.org/TR/REC-CSS2/grammar.html

Following the formal grammar of CSS 1 is a little more complicated,  
but it seems that the leading dash is allowed by the grammar, even if  
disallowed by the text in the specification. (CLASS defined as  
"."{name} with NAME being {nmchar}+ and NMCHAR including the dash.)

-- CSS 1 grammar: http://www.w3.org/TR/REC-CSS1#appendix-b

Michel Fortin
michel.fortin at michelf.com

More information about the whatwg mailing list