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

Can identifier names start with a hyphen?

From: XStandard <lists@xstandard.com>
Date: Thu, 16 Mar 2006 17:57:58 -0500
To: <www-style@w3.org>
Message-ID: <o7bn2w0g7oy7x2c.160320061757@pinscher>

Sorry if this has already been asked. Can identifier names (classes and IDs) start with a hyphen?

This is why I got confused:

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

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.

This seems to contradict the previous statement and says that IDs like "-abc" are invalid.

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}

Received on Thursday, 16 March 2006 22:58:01 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:27:23 UTC