I recently needed to apply a tweak for IE v5 only. I resolved the issue by using conditional comments to supply a CSS repair file to IE v5 only.

The format is:

<!--[if "condition" IE "version number"]>
<p>Only IE displays this text if the condition is met</p>
<![endif]-->

There are 6 conditions that can be applied (there's a "logical not" case too):

  1. [if IE] - if above or equal to version 5
  2. [if IE 6] - if equal to version 6
  3. [if lt IE 6] - if less than version 6
  4. [if lte IE 6] - if less than or equal to version 6
  5. [if gt IE 6] - if greater than version 6
  6. [if gte IE 6] - if greater than or equal to version 6

The above will work on IE 7 and 8 too.

Valid version numbers are 5, 5.5, 6 and 7. Version 8 will follow suit. Though there is support for specific version numbers such as 5.0453

I found it very useful for adding a style for IE v5 only:

<!--[if IE 5]>
<style type="text/css">@import "IE5_only.css";</style>
<![endif]-->

Here's an example of targeting non-IE browsers:

<!--[if !IE]><!-->
<p>This is not Internet Explorer</p>
<!--<![endif]-->

Here's an example of targeting non-IE browsers and IE 7 or above:

<p>You are using
<!--[if gte IE 7]>
  At least IE7 and not
<!-->
  a non-IE browser
<!--<![endif]-->
</p>

Further information is available from Microsoft or search Google.

Validators do not check the code inside the comments so take care.

Since originally writing this snippet it has become the standard method for dealing with IE irregularities.