Conditional comments are conditional statements interpreted by Microsoft Internet Explorer versions 5 through 9 in HTML source code. Conditional comments can be used to provide and hide code to and from Internet Explorer. Conditional comments are no longer supported in IE10 and IE11.
Conditional comments in HTML first appeared in Microsoft's Internet Explorer 5 browser, although support has now been deprecated. In Internet Explorer 10 HTML conditional comments are not supported when the page is in standards mode (document mode 10). JScript conditional comments were introduced in Internet Explorer 4 and they continue to be supported in Internet Explorer 10, in standards mode or compatibility mode.
Here is a simple example that demonstrates how conditional comments work.
There are two types of "conditional comments": downlevel revealed, and downlevel hidden.
The basic syntax of each type of comment is shown in the following table. The first comment shown is the basic HTML Comment, which is included for the purpose of comparison and to illustrate the different syntax used by each type of conditional comment.
The HTML shown inside the syntax block in each of the conditional comments denotes any block of HTML content, including script. Both types of conditional comment use a conditional expression to indicate whether the content inside the comment block should be parsed or ignored. The conditional expression is formed from a combination of feature, operator, and/or value, depending on the feature. The following table shows the supported features and describes the values each feature supports.
The following table describes the operators that can be used to create conditional expressions.
Below are two examples of a "downlevel hidden" conditional comment:
or
The directive in the first example will let IE 8 read the specified CSS file, while IE 7 or older IE versions will ignore it. Browsers other than IE will also ignore it because it looks like a standard HTML comment. The tag in the second example will let IE versions 5.0 through 7 read the internal CSS style. With different uses of this tag you can also single out IE 6, IE 5, or versions of IE that are newer (greater) or older (less) than a specified version.