W3C home > Mailing lists > Public > www-style@w3.org > March 2006

Re: Can identifier names start with a hyphen?

From: L. David Baron <dbaron@dbaron.org>
Date: Thu, 16 Mar 2006 16:27:36 -0800
To: www-style@w3.org
Message-ID: <20060317002736.GA4685@ridley.dbaron.org>
On Thursday 2006-03-16 17:57 -0500, Vlad Alexander wrote:
> 
> Sorry if this has already been asked. Can identifier names (classes
> and IDs) start with a hyphen?

Identifiers in general and classes and IDs specifically are two
different things.

> [spec source: http://www.w3.org/TR/CSS21/syndata.html]
> In CSS 2.1, identifiers  (including element names, classes, and IDs in selectors) can contain only the characters [A-Za-z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, or a hyphen followed by a digit.
> [/spec]

This describes the general rules for identifiers, and gives some
examples of things that are identifiers.

> That's clear. IDs like "-abc" are okay but "-0abc" are not. The spec then reads:
> 
> [spec source: http://www.w3.org/TR/CSS21/syndata.html]
> Only properties, values, units, pseudo-classes, pseudo-elements, and at-rules may start with a hyphen (-); other identifiers (e.g. element names, classes, or IDs) may not.
> [/spec]
> 
> This seems to contradict the previous statement and says that IDs like "-abc" are invalid.

This is intended to further restrict the definition for "other
identifiers" to something stricter than that for identifiers in general.
Considering that this sentence immediately follows the previous one, I
think it's reasonably clear that it's adding further restrictions to the
previous sentence.

> I ran the following 2 rules through the W3C CSS validator and according to the validator, both are valid:
> 
> #-abc {color:red}
> #-0abc {color:red}

The validator is not a reference implementation, and it's not even a
particularly well-maintained implementation, so that's pretty much
irrelevant.

-David

-- 
L. David Baron                                <URL: http://dbaron.org/ >
           Technical Lead, Layout & CSS, Mozilla Corporation

Received on Friday, 17 March 2006 00:27:54 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:44 GMT