The Underscore Hack
The Underscore Hack is a useful looking CSS hack. IE/Win ignores an underscore (_) at the beginning of any CSS property name, interpreting the declaration as if the underscore wasn’t there. Other browsers do not recognise the property and ignore the declaration. Note that underscores used to be illegal in CSS identifiers and properties, but that was changed in CSS 2.1. (via Mike Davidson)
- Previous post: Stateless: Art of No State
- Next post: Web standards elitism
Information, sponsorship, and externals
About the author
Roger Johansson is a Swedish web professional specialising in web standards, accessibility, and usability. More about me and this site.
Latest articles
- Validation statistics from Nikita the Spider Comments off
- An analysis of the sites crawled by the bulk validation tool Nikita the Spider during March 2008.
- Authentic Jobs API and Affiliates program Comments off
- The Authentic Jobs job listing service now has a public API and an affiliate program.
- What does Acid3 mean to you and me? Comments off
- Opera and Apple have announced that their web browsers pass the Acid3 Browser Test, but how will that help web designers and developers?
- Designing Web Navigation (Book review) Comments off
- Learn the fundamentals of navigation design and design better navigation systems for large and small sites as well as for web based applications.
- DOMAssistant bundle for TextMate Comments off
- To save keystrokes and speed up development I have created a DOMAssistant bundle for TextMate.
- First impressions of Internet Explorer 8 Beta 1 Comments off
- My impressions after trying out Internet Explorer 8 Beta 1 for a couple of days.









Comments
The exact wording of the specs is that a leading underscore or dash designates a proprietary extension, so now you can have _scrollbar-face-color (or -scrollbar-face-color, it's the same): #fff without feeling guilty. Neat.
I'd rather suggest using
instead of the underscore hack for injecting the rule to IE only...
Damn, it should have been '*' - an asterisk...
Pretty old and well-known in Central Europe, but still useful. There are some doubts about the validity though.
I´ve been using the "*" html foo hack for some time now. Think it works ok, by using the _ hack instead I would save 5 characters per hack. Goddie ;)
I've been using the "*" html hack too. Not sure if I'll use this instead -- I just wanted to make a note of it.
djn: You may still need to feel guilty for messing with your visitors' browser UI ;)
Unfortunately, the underscore hack makes the W3's CSS validator throw an error or two. I'd prefer not to use that one.
I've had success with "* html", "html>body", and "w\idth" used together or separately.
The underscore hack has a step-brother, asterisk attribute, i.e. asterisk margin. We've gotta watch these things with IE7!
Start avoiding the good ol' '*' html filter, that is certainly going to be ignored by IE7.
Sorry, comments are closed for this post.