Conditional comments of IE

Conditional Comments (CC) is basically a new set of comment-like tags that IE 5+ supports. These tags look very much like the good old comment tag- and in fact are treated as such by all browsers except IE, in which they operate a little more intelligently. Using CC, you can selectively "comment out" any portion of your page in a way that only IE interprets the containing content, or the other way around, so all browsers except IE 5+ gets to open up the Pandora box. Here are the basic two new tags of IE that make this possible:

<!--[if IE]>
You are using IE (IE5+ and above).

<![if !IE]>
You are NOT using IE.

Take a long and hard look at the above tags, and you should discern the ingenuity behind them. To display content that will only be rendered and seen by IE 5+ browsers, wrap the content using CC tag #1. To have content displayed to all browsers but IE 5+, use CC tag #2 instead.

Detecting IE5.5 and IE6

It is possible for your conditional comment to serve HTML code to only a certain version of IE, such as IE5.5 or IE6. Here is an example of each:

<!--[if IE 5.5000]>
You are using IE 5.5!
<!--[if IE 6]>
You are using IE 6!

Notice how we input the version 5.5- as 5.5000. This four digit definition is called version vector, and is required whenever the version to detect is a subset of an integer.

Taking your detection further

Operators is what CC relies on to determine it course of action. We saw above how one operator, "!", is used to negate the browser version to detect. In fact CC supports a handful of other operators, which we shall list and then explain:

Operators supported by CC
Operator syntax Description
! The "not" operator.
lt The "less than" operator.
lte The "less than or equal to" operator.
gt The "greater than" operator.
gte The "greater than or equal to" operator

With the above operators more generic detection of browsers such as IE6+ (which encompasses IE6, IE6.1, IE7, and so on) becomes possible. For example:

<!--[if gte IE 6]>
You are using IE 6+