Conditional CSS for Internet Explorer

To add stylesheets for specfic Internet Explorer versions you can add the blocks of code below to the head section of your HTML code. Make sure the code is placed beneath your main css declarations.

All IE Versions

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie-all.css" />
<![endif]-->

IE6

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->

IE7

<!--[if IE 7]> 
<link rel="stylesheet" type="text/css" href="ie7.css">
<![endif]-->

You can also use other operators to target various version at the same time:

lt = less than
lte = less than or equal to
gt = greater than
gte = greater than or equal to
! = not equal to
& = AND [if (gt IE 6)&(lt IE 7)]
| = OR [if (IE 6)|(IE 7)]

Less or equal to IE8

<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->

Leave a Reply

Your email address will not be published. Required fields are marked *