Conditional comment explained

Conditional comments are conditional statements interpreted by Microsoft Internet Explorer versions 5 through 9 in HTML source code. They can be used to provide and hide code to and from these versions of Internet Explorer. Conditional comments are not supported in Internet Explorer 10 and 11.

Conditional comments in HTML[1] 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).[2] JScript conditional comments were introduced in Internet Explorer 4, and they continued to be supported in Internet Explorer 10, in standards mode or compatibility mode.

Examples

Here is a simple example that demonstrates how conditional comments work.

Syntax

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.

Comment typeSyntax or possible value
standard HTML comment
downlevel-hidden
downlevel-revealed
The 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 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.

Notes and References

  1. Web site: About Conditional Comments. Microsoft Corporation. 2007-10-24. https://web.archive.org/web/20081013121554/http://msdn2.microsoft.com/EN-US/library/ms537512.aspx. 2008-10-13. dead.
  2. Web site: HTML5 Parsing in IE10. 2011-07-06. Microsoft Corporation. https://web.archive.org/web/20160420083101/https://blogs.msdn.microsoft.com/ie/2011/07/06/html5-parsing-in-ie10/. 2016-04-20.