Noscope is a bi-weekly journal serving up snacksized portions of pointless stuff since 2001. On a new linode server!
I also do freelance design and usability via dejligt.com

Showing CSS to IE only (The Underscore Hack) [Update]

    13:05 on January 23, 2005 , ,

This page details an inline CSS hack for Internet Explorer 6 on Windows. You can also find an extended version of this hack that works for Internet Explorer 6, 7 and 8.

The best idea, however, would be to serve a separate stylesheet for each browser you’re hacking to.

Recently, I stumbled upon (via Mr. van Kesteren) the best CSS “hack” you’ll ever use in CSS sites.

It allows you to show CSS to Internet Explorer only, omitting Mozilla, Safari and Opera.

This is different from conditional comments in the following way:

  • It allows you to write conditional CSS directly in your stylesheet file, and doesn’t require inline styles
  • It works for IE 5.0, 5.5 and 6.0
  • It’s a hack
  • It’s very simple to work with.

The hack is called the “Underscore Hack”, and apparently it’s been around for a while. For the benefit of those of us who didn’t know about it, I’m posting it here:

body {
    background: green; /* show to Mozilla/Safari/Opera */
    _background: red; /* show to IE */
}

Cons

Sample Page

View sample page, including CSS

More Information on CSS filtering

John Serris has done an indepth write-up on various other methods of filtering CSS. It is definitely worth a visit:

Managing CSS Hacks

Pings

Comments