W3C home > Mailing lists > Public > www-validator-css@w3.org > May 2002

Re: CSS Validator doesn't like "_" characters in the ID of a style definition

From: Philippe Le Hegaret <plh@w3.org>
Date: 20 May 2002 14:09:29 -0400
To: "Lyders, Richard" <Richard.Lyders@Airliquide.com>
Cc: "'www-validator-css@w3.org'" <www-validator-css@w3.org>
Message-Id: <1021918170.6807.67.camel@jfouffa>
On Wed, 2002-04-17 at 13:22, Lyders, Richard wrote:
> According to http://www.w3.org/TR/REC-html40/types.html#type-name
> <http://www.w3.org/TR/REC-html40/types.html>: 
> 	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 ("."). 
> Thus, I read this to mean that I should be able use the underscore to create
> a valid ID such as: 
> 	ID="HEADER_MENU". 
> Thus if it is a valid ID, then I should be able to use it in a style
> definition as below: 
> 	table.Y#HEADER_MENU {
> 	background: yellow;
> 	}
> As expected, everything seems to work properly when I use the above ID in
> the style definition, but when I test it in your CSS Validator I get the
> following parse error: 
> 	Errors
> 	URI : file://localhost/S:\BVD\4002\scr9259\misc\testHeaderMenu.css
> <file://localhost/S:/BVD/4002/scr9259/misc/testHeaderMenu.css>
> *	Line: 3 Context : table.Y#HEADER 
> 			Parse Error - #HEADER_MENU { background: yellow; } 
> If I replace the underscore "_" with a dash "-", then the validator gives no
> errors. 
> If there really something wrong with my use of the underscore in HEADER_MENU
> ID in the style definition or is this just a bug in the validator? 

It is true that _ are perfectly valid for HTML or XML documents.
However, the CSS 2 grammar [1] defines them using the HASH token, which
is defined as follow:

nonascii	[\200-\377]
unicode		\\{h}{1,6}[ \t\r\n\f]?
escape		{unicode}|\\[ -~\200-\377]
nmchar		[a-z0-9-]|{nonascii}|{escape}
name		{nmchar}+
"#"{name}		{return HASH;}

Therefore, '_' is not valid as an identifier for CSS2.

Philippe

[1] http://www.w3.org/TR/CSS2/grammar.html
Received on Monday, 20 May 2002 14:09:35 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 27 June 2012 00:14:11 GMT