Last Comment Bug 12385 - CSS idents can't start with "-"
: CSS idents can't start with "-"
[css2.1] (see comment 23)
: css2, testcase
Product: Core
Classification: Components
Component: CSS Parsing and Computation (show other bugs)
: Trunk
: All All
: P3 normal (vote)
: Future
Assigned To: Nobody; OK to take it and work on it
: Jet Villegas (:jet)
Depends on:
  Show dependency treegraph
Reported: 1999-08-24 08:58 PDT by David Baron :dbaron: ⌚️UTC-10
Modified: 2007-07-31 20:01 PDT (History)
14 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

testcase (213 bytes, text/html)
2000-08-27 12:56 PDT, hidden
no flags Details

Description David Baron :dbaron: ⌚️UTC-10 1999-08-24 08:58:15 PDT
DESCRIPTION:  CSS2 identifiers can't start with dash (0-9 and - are the
characters that can't start an identifier but can be in the middle).  I know
you're using -moz to begin identifiers that represent extensions, but (unless
this will be changed in CSS3), you shouldn't allow classes, etc., that begin
with a -.  That is:

.-d { font-weight: bold; }

should be ignored.


ACTUAL RESULTS: Fifth bulleted item has two words in bold.

EXPECTED RESULTS: Fifth bulleted item should not have any words in bold.

 * Linux, apprunner, 1999-08-20-13-M10
Comment 1 David Baron :dbaron: ⌚️UTC-10 1999-08-24 16:29:59 PDT
 * Windows, apprunner, 1999-08-24-09-M10
Comment 2 Peter Linss 1999-08-24 17:25:59 PDT
CSS3 allows idents to start with dashes (explicitly to allow the extension
mechanism). Need to evaluate if this should apply to class names (and a few
other places where ident is allowed.
Comment 3 Christine Hoffman 1999-08-24 17:31:59 PDT
Verifying this LATER.
Comment 4 Pierre Saslawsky 1999-11-13 02:40:59 PST
Reassigning peterl's latered bugs to myself.
Comment 5 Christine Hoffman 1999-11-16 17:29:59 PST
Is this still latered? If not, please remove resolution. If not, I will verify
it again.
Comment 6 Pierre Saslawsky 1999-11-16 17:58:59 PST
Yep, still latered.

In case we (er... when we) look into it again, Ian posted some useful info about
errata to the CSS syntax under bug 18936.
Comment 7 Christine Hoffman 1999-11-17 10:55:59 PST
Verified LATER.
Comment 8 Hixie (not reading bugmail) 2000-01-13 16:00:59 PST
Migrating from {css1} to css1 keyword. The {css1}, {css2}, {css3} and {css-moz}
radars should now be considered deprecated in favour of keywords.
I am *really* sorry about the spam...
Comment 9 Hixie (not reading bugmail) 2000-06-07 14:01:51 PDT
Reopening and moving to Future...
Comment 10 Tobias Burnus 2000-08-05 08:21:42 PDT
I think it would be nice, if it would have an milestone (instead of Future)
assigned since Mozilla claims to support CSS fully.
See also:
and specs:
Comment 11 hidden 2000-08-27 12:56:42 PDT
Created attachment 13574 [details]
Comment 12 hidden 2000-08-27 12:57:37 PDT
added testcase
Comment 13 Kurt Weinschenker 2000-10-05 17:53:47 PDT
Tried on Mac OS 9.0.4,
Mozilla build 2000100208-M18, still doesn't work.

(CSS1 Test Suite:  1.5 ID as selector)
Comment 14 Hixie (not reading bugmail) 2001-02-12 16:40:38 PST
Netscape's standard compliance QA team reorganised itself once again, so taking 
remaining non-tables style bugs. Sorry about the spam. I tried to get this done 
directly at the database level, but apparently that is "not easy because of the 
shadow db", "plus it screws up the audit trail", so no can do...
Comment 15 Daniel Glazman (:glazou) 2001-08-27 05:11:57 PDT
Changing URL to my test suite since my publisher modified its web site
architecture w/o notification :-(
Comment 16 David Baron :dbaron: ⌚️UTC-10 2002-06-19 21:05:36 PDT
Assigning pierre's remaining Style System-related bugs to myself.
Comment 17 Boris Zbarsky [:bz] (still a bit busy) 2002-08-11 03:01:07 PDT
Has the WG decided anything here yet?
Comment 18 Karl Ove Hufthammer 2002-08-11 10:24:14 PDT
> Has the WG decided anything here yet?

I don't know, but they have at *not* allowed the
'-' character in the CSS 2.1 WD, released ~a week ago
<URL: >.
Comment 19 Boris Zbarsky [:bz] (still a bit busy) 2002-08-11 19:00:37 PDT
Yes... but this is not a CSS2 issue.  This is a question of what CSS3 will say
(since CSS2 also does not have the -vendor-ident mechanism in place).
Comment 20 Anne (:annevk) 2004-03-05 08:11:01 PST
CSS2.1 does: <>
Comment 21 Boris Zbarsky [:bz] (still a bit busy) 2004-03-05 08:50:48 PST
Yeah, at this point this looks invalid.
Comment 22 David Baron :dbaron: ⌚️UTC-10 2004-03-05 09:35:26 PST
"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." (4.1.3)
Comment 23 Anne (:annevk) 2004-03-05 10:22:10 PST
To summarize: this is a valid bug, since Mozilla supports something it should
not support (.-d).
Comment 24 Justin Wood (:Callek) 2004-06-23 21:12:37 PDT
hmm iirc recently we had a problem with calendar class names (which started with

iirc we warn about it in debug builds, perhaps we can make the warning into an
Comment 25 Gérard Talbot 2007-06-25 12:29:27 PDT
Latest CSS 2.1 WD (06 November 2006) suggests that IDs can start with an hyphen (-) and then may be followed by an alphabetic character [A-Za-z] or may then even be followed by an underscore (_).

In CSS, identifiers  (including element names, classes, and IDs in selectors) can contain only the characters [a-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.
CSS 2.1, Working Draft 06 November 2006, Section 4.1.3 Characters and case

ident		-?{nmstart}{nmchar}*
nmstart		[_a-z]|{nonascii}|{escape}
CSS 2.1, Working Draft 06 November 2006, G.2 Lexical scanner

To make things worse,
CSS 2.1, Working Draft 06 November 2006, section G.3 Comparison of tokenization in CSS 2.1 and CSS1 at
In CSS1, a class name could start with a digit (".55ft")
while CSS 1 spec says
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;

Finally, HTML 4.01 claims that
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by
any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons
(":"), and periods (".").

Did I miss something? 
I'm voting for this bug :)
Comment 26 Gérard Talbot 2007-06-25 13:21:40 PDT
<p id="-asdf">

Both the HTML 4.01 spec and W3C HTML validator say this attribute value is invalid


#-asdf { color: red }
is fine and ok with latest CSS 2.1 WD and with the W3C CSS validator
Comment 27 Gérard Talbot 2007-06-26 11:58:28 PDT
Complete testcase for this bug:
Comment 28 Boris Zbarsky [:bz] (still a bit busy) 2007-06-26 18:47:03 PDT
We pass that testcase, no?
Comment 29 Gérard Talbot 2007-06-27 10:52:33 PDT
If we meticulously follow and comply with the latest CSS 2.1 (6 nov. 2006) WD, then yes, we pass that testcase.

I wish all CSS 2.1 WD would not have introduced exceptions and unneeded complexity and just carried on with the CSS1 and simple 
"selectors (element names, classes and IDs) (...) can not start with dash or digit".
Those kind of new CSS 2.1 exceptions encourage and promote invalid markup code as invalid attribute specifications are to be honored nevertheless in CSS 2.1.
Comment 30 Ray Kiddy 2007-07-22 16:11:13 PDT
FYI: There is a CSS 2.1 test that fails that is, I believe, from this bug.

The source has:

  .one { color: green; background: white; }
  .-ident, .one { color: red; }

  .two { color: green; background: white; }
  #-ident, .two { color: red; }

In both cases, the text should be green, but it is red.

Looking at:

All the others pass.
Comment 31 Gérard Talbot 2007-07-23 12:58:42 PDT

The previous and current/latest [July 19th 2007, CR] CSS 2.1 spec says:
"in CSS, identifiers  (including element names, classes, and IDs in selectors) can contain only the characters [a-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."

Also, current (and previous) CSS 2.1, Section 4.1.1 Tokenization
still gives
ident 	[-]?{nmstart}{nmchar}*
nmstart [_a-z]|{nonascii}|{escape}

So, they can start with an hyphen as long as their next character is not a digit. E.g.: 

#-_ {color: red;}
is perfectly valid CSS 2.1

#-foo {color: red;}
is perfectly valid CSS 2.1

.-bar {color: red;}
is also perfectly valid CSS 2.1

and so is -ident since "i" is not a digit.

This is the CSS validator report according to CSS 2.1 profile of the t040103-ident-03-c.htm webpage:

As far as I can see, both sentences in
should be red, not green. That test needs to be updated.
Comment 32 Gérard Talbot 2007-07-23 13:20:34 PDT
As far as I'm concerned, 
- this bug should be resolved as WORKSFORME, 
- the summary should be updated so that we don't mislead bug reporters 
- I. Hickson should also be informed that one of his test 
may not be correct.
Comment 33 fantasai 2007-07-31 20:01:28 PDT
The restriction on starting hyphens in identifiers was removed.
The resolution was for issue 167 in issues-3, in response to
The discussion is minuted in
where it basically says there's interop on supporting hyphens at the beginning of class names and the restriction is confusing anyway.

Marking INVALID.

Note You need to log in before you can comment on or make changes to this bug.