HTML <!-- .[ ].. --> (Conditional Comment) Tag

❮ Previous Reference Next ❯

Conditional comments are not supported in Internet Explorer 10 and 11.

Example

<!--[if IE 5]>
<link rel="stylesheet" href="ie5.css" type="text/css" media="screen">
<![endif]-->

Meaning

Conditional Comment is Internet Explorer–specific comment style can be used to mask or include content, depending on the browser in play.

Conditional comments are often used to link special Internet Explorer–specific style sheets or to include scripts solely for these browsers.

Note: Conditional comments are only supported in Internet Explorer versions 5 through 9.


Standard Syntax

Hide content if not supported:
<!--[if expression]> HTML <![endif]-->

Show content if not supported:
<![if expression]> HTML <![endif]>



Browser Support




Status







Type of conditional comment.

Comment type Syntax or possible value
standard HTML comment <!-- Comment content -->
downlevel-hidden <!--[if expression]> HTML <![endif]-->
downlevel-revealed <![if expression]> HTML <![endif]>


The following table shows the supported features and describes the values each feature supports.

Item Example Comment
IE [if IE] The string "IE" is a feature corresponding to the version of Internet Explorer used to view the Web page.
value [if IE 7] An integer or floating point numeral corresponding to the version of the browser. Returns a Boolean value of true if the version number matches the browser version. For more information, see Version vectors.
WindowsEdition [if WindowsEdition] Internet Explorer 8 on Windows 7. The string "WindowsEdition" is a feature corresponding to the edition of Microsoft Windows used to view the Web page.
value [if WindowsEdition 1] An integer corresponding to the edition of Windows used to view the Web page. Returns a Boolean value of true if the value matches the edition being used. For information about supported values and the editions they describe, see the pdwReturnedProductType parameter of the GetProductInfo function.
true [if true] Always evaluates to true.
false [if false] Always evaluates to false.


The following table describes the operators that can be used to create conditional expressions.

Item Example Comment
! [if !IE] The NOT operator. This is placed immediately in front of the feature, operator, or subexpression to reverse the Boolean meaning of the expression.
lt [if lt IE 5.5] The less-than operator. Returns true if the first argument is less than the second argument.
lte [if lte IE 6] The less-than or equal operator. Returns true if the first argument is less than or equal to the second argument.
gt [if gt IE 5] The greater-than operator. Returns true if the first argument is greater than the second argument.
gte [if gte IE 7] The greater-than or equal operator. Returns true if the first argument is greater than or equal to the second argument.
( ) [if !(IE 7)] Subexpression operators. Used in conjunction with boolean operators to create more complex expressions.
& [if (gt IE 5)&(lt IE 7)] The AND operator. Returns true if all subexpressions evaluate to true
| [if (IE 6)|(IE 7)] The OR operator. Returns true if any of the subexpressions evaluates to true.
❮ Previous Reference Next ❯