While this popular question, and it's answers cover a fair bit of ground on the subject, I'm curious about what constitutes a valid class name in the wild (at the time of this writing).
<edit>
To expand on this, as it is the core of my concern, are we not at a point in the evolution of user-agent technology and standard support, that certain naming hacks can be abandoned, instead re-purposing them for robustness in common use? Understandably, there will always be edge-cases (someone is probably using NN6, with no intention to stop) but I'm an advocate of making things work as expected (read: as pixel-perfect as possible) in 90% of browsers, expecting that the remainder will have an "acceptable" experience. </edit>
Namely, prefixing (or general use of) underscores (_
) and hyphens (-
). While the CSS spec goes on to say that with escaping, essentially any character (save for NUL
) is valid, validity is only as good as it's corresponding support.
So, in the current browser landscape, what are the "do's" and "do not do's" of CSS class naming? Would it be unwise to use any of the following:
.foo { } /* for completeness... */
.foo-bar { } /* hyphenated */
.foo_bar { } /* underscored */
.foo-bar-baz { } /* multi-hyphenated */
.foo-bar_baz { } /* hyphenated then underscored */
.foo_bar-baz { } /* underscored then hyphenated */
.-foo { } /* leading hyphen */
.-foo-bar { } /* leading hyphen and hyphenated */
.-foo_bar { } /* leading hyphen and underscored */
._foo { } /* leading underscore */
._foo_bar { } /* leading underscore and underscored */
._foo-bar { } /* leading underscore and hyphenated */
While escaping is of course an option, I don't think it's feasible for anything more than a trivial implementation. My concern with underscores and hyphens comes from their prevalence of use, but (seemingly) inconsistent support across browsers; at least historically.