Forum Moderators: not2easy

Message Too Old, No Replies

Underscores in class names

Why are they a problem?

         

GaryK

5:04 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This question came up in another thread and despite some helpful people I could not find a definitive answer to the following question.

Why should I avoid underscores in class names?

I've heard it affects SEO and I've heard some browsers have a problem with it. Is there any truth to either of these assertions?

Thanks.

drbrain

6:30 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



They are a CSS2 errata item, and not allowed in CSS1, so early CSS2 implementations may not support the underscore in class names.

References:

CSS2 Appendix D: The grammar of CSS2 [w3.org]
CSS1 Appendix B: CSS1 Grammar [w3.org]
Errata in REC-CSS2-19980512 [w3.org] (see "section 4.1.1 (and D.2)")

drbrain

6:33 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As to the SEO aspect, it probably is similar reasoning as the example.com/path-name vs example.com/path_name debate for SEs that index the raw text.

GaryK

7:30 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks so much. The second link was especially helpful.

If I understand correctly, avoiding underscores in CSS is done primarily for backwards compatibility.

I tend to use the underscore as a way of combining classes into groups of similar items, such as:

table.Border_Left,
table.Border_Right,

and so on, with the appropriate properties for each. This gives me great flexibility with my tables - I display a lot of tabular data.

Am I correct that in the above examples I should replace the underscores with hyphens?

drbrain

7:42 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I doubt you'll find many CSS1-only user agents in the wild anymore. I don't worry about it, if you are still worried, check your browser stats.

GaryK

9:15 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since I maintain a browscap.ini file I can tell you reliably that on average 95% of the user agents I see in the log files for my websites are CSS2 compatible. The rest are more often than not search engines and general crawlers. But there are some legitimate browsers in the lot including very old versions of IE and NS.

Unless I really need to get rid of the underscore, and given my audience it doesn't seem like it, I'm going to concentrate on bigger issues.

Thanks again for your help. It's much appreciated.