Conditional Comments for Internet Explorer

Test of Filter

This text will be green if the rule has been applied.

Code Syntax


<!--[if IE]>
   <style type="text/css">
   /*<![CDATA[*/ 
   #testElement {
      color: #00cc00;
      }
   /*]]>*/
   </style>
<![endif]-->
         

Browser Support / Behaviour

Applied By

Not Applied By

Special Notes

Conditional comments were introduced in IE5 (on Windows) to allow the inclusion of some HTML into a document if a simple condition regarding browser version is satisfied. All conditional comments have the following syntax:


<!--[if ( ! )* ( comparison )* IE ( version number )* ]>
HTML content to parse if the condition is true goes here
<![endif]-->
         

The comparison is any one of the 4 comparison operators: lt (less than), lte (less than or equal to), gt (greater than), or gte (greater than or equal to). Note that, if you use any of the comparision operators, you must specify a version number. If a comparison operator is left out, equality is assumed and a version number is not needed. The version number is any valid integer or floating point browser version number (though the only valid values right now are 5, 5.5000, and 6).

By wrapping an embedded stylesheet in conditional comments, you can make the styles apply only to IE5+ on Windows. Below are a number of ways to write conditional comments to target specific combinations of IE5+ browsers:

<!--[if gte IE 5]>
IE 5.0 - 6.x
<!--[if IE 5]>
IE 5.0
<!--[if IE 5.5000]>
IE 5.5
<!--[if IE 6]>
IE 6.0
<!--[if gte IE 5.5000]>
IE 5.5 - 6.x
<!--[if lt IE 6]>
IE 5.0 - 5.5

Note that the downlevel-revealed form of conditional comment (<![if IE]>...<![endif]>) which allows non IE5 Windows browsers to view the commented HTML (which would be helpful in hiding CSS from IE5+ Windows but not from other browsers) will not validate.

More information