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)

  • November 6, 2004
  • Comments closed
  • Posted in

Comments

1. November 7, 2004 by djn

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.

2. November 7, 2004 by JohnyB

I'd rather suggest using

  • html foo {...}

instead of the underscore hack for injecting the rule to IE only...

3. November 7, 2004 by JohnyB

Damn, it should have been '*' - an asterisk...

4. November 7, 2004 by dusoft

Pretty old and well-known in Central Europe, but still useful. There are some doubts about the validity though.

5. November 8, 2004 by Jens Wedin

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 ;)

6. November 8, 2004 by Roger Johansson

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 ;)

7. July 4, 2005 by Tim McCormack

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.

8. November 29, 2005 by Ted Drake

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.

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.

Subscribe

Looking for web hosting?

Try DreamHost!

Use the promo code 456BEREASTREET3 to save USD 20 when you sign up!

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.

More articles

Favourites, here and elsewhere

Affiliation

  • NetRelations
  • Kaffesnobben
  • Dagens recept
  • 9rules network member

Support this site

Show your support by buying a book or two from SitePoint or getting me something from my Amazon Wish List.