Making IE Specific CSS or Code (Conditional Comments)

April 25th, 2004 by Joen , , , ,

This page details the generally most accepted solution to serving up custom stylesheets for versions of Internet Explorer. As such, using conditional comments is arguably the most recommended way to “hack”.

You can also find an inline CSS hack for Internet Explorer 6 and 7.

While recently giving Titoonics Sporkle gamesite a makeover, I made an Internet Explorer 5.0 and 5.5 specific CSS stylesheet.

While it is a pain to develop for archaic browsers, Internet Explorer on Windows platforms support a fairly straight-forward and simple method, that’s not even a hack.

As a webdesigner, it is quite a challenge to design and build a site that is supposed to attract many viewers on many platforms. I can’t just choose to design for the latest and greatest. Decisions on what one wants support, must be made, and the design should ideally “degrade gracefully” on unsupported browsers.

CSS For Older Than Internet Explorer 6

In my case, I needed a stylesheet specifically for Windows browsers older than Internet Explorer 6.

Thus, this piece of code came to the rescue:

<!--[if lt IE 6]>
<style>
@import url("/oldbrowser.css");
</style>
<![endif]-->

In human tongue, it says “if browser is less than IE 6, use this stylesheet”.

CSS For All Versions Of Internet Explorer (Windows)

If you just want to attach a stylesheet, or display a chunk of code to all versions of Internet Explorer, you can use this code:

<!--[if IE]>
<style>
@import url("/ie.css");
</style>
<![endif]-->

CSS Not Shown To Internet Explorer 6

This is useful, for instance, if you want to serve a stylesheet free version of your site to IE6 users.

<![if !(IE 6)]>
<style>
@import url("/not_ie.css");
</style>
<![endif]>

There are many more of these “out commenting”, or tricks for you to refine your stylesheets. For a complete list, I have to redirect you to this document on conditional comments.


Websites linking to this post:

  1. Joseph Scott’s Blog » Blog Archive » IE Specific CSS

Comments (6)

  1. nebon says:

    I am trying to use this code.. On a mac IE 5.5.
    And I cant let this work ...

    Any suggestions ?

    Quote

  2. Sigge (subscribed) says:

    i was just trying it too on mac, and its running same version, cant get it to work either.

    Quote

  3. Sigge (subscribed) says:

    hehe, just looked at when u posted this , well four years later .. you got any solution ? :D

    Quote

  4. Sigge: Yes, the old IE 5 Mac backslash hack:
    /* import stylesheets and hide from ie/mac \*/
    @import url("screen.css");
    /* end import and hide */

    Read more here:
    http://www.simplebits.com/notebook/2009/02/13/iegone.html

    Quote

Comment

(required)

(required)

Textile

Textile is a method that uses simple symbols to quickly write rich text markup. These are the most common:

  • _emphasis_
  • *strong*
  • -deleted text-
  • !imageurl.gif!