[thelist] Rules for CSS Style Names

MRC webmaster at equilon-mrc.com
Fri Mar 15 11:01:00 CST 2002


Andy,

> Straight from the source:
>
> "In CSS2, identifiers  (including element names, classes, and IDs in
> selectors) can contain only the characters [A-Za-z0-9] and ISO 10646
> characters 161 and higher, plus the hyphen (-); they cannot start with a
> hyphen or a digit."
>
> http://www.w3.org/TR/REC-CSS2/syndata.html#q4

    True, except that this was amended in the CSS 2 errata document last
year to include underscores [1]. The problem is that a number of legacy
browsers do not handle underscores because they were for quite some time
considered illegal (however IE/Win32 has always allowed them, I believe).
So, the bottom line: underscores _are_ legal in id and class names, but
their use is ill-advised unless the developer knows that they are actually
supported in targeted browsers (such as on an Intranet).
    Eric Meyer has written a pretty good article on using the underscore in
class and id names on Netscape's DevEdge site [2].

James Aylard

1. http://www.w3.org/Style/css2-updates/REC-CSS2-19980512-errata.html#x3
2. http://developer.netscape.com/evangelism/docs/technotes/css-underscores/




More information about the thelist mailing list