It is proposed that this article be deleted because of the following concern:
If you can address this concern by improving, copyediting, sourcing, renaming, or merging the page, please edit this page and do so. You may remove this message if you improve the article or otherwise object to deletion for any reason. Although not required, you are encouraged to explain why you object to the deletion, either in your edit summary or on the talk page. If this template is removed, do not replace it . ContentsThe article may be deleted if this message remains in place for seven days, i.e., after 12:34, 31 May 2025 (UTC). Find sources: "Conditional comment" – news · newspapers · books · scholar · JSTOR Nominator: Please consider notifying the author/project: {{ subst:proposed deletion notify |Conditional comment|concern=Fails [[WP:GNG]]}} ~~~~ |
In Internet Explorer (IE) versions 5 through 9, a conditional comment is text formatted as a comment in HTML source code with special syntax that IE interprets as a conditional statement. A conditional comment specifies whether to include or exclude code based on the evaluation of a conditional expression and is generally used to support different versions of IE or a browser other than IE. [1]
Support for conditional comments was introduced in IE version 5 and dropped in version 10. In IE 10, conditional comments are not supported when the page is in standards mode (document mode 10). [2] There exists an adjacent technology in JScript (Microsoft's non-standard implementation of JavaScript) called conditional compilation, which uses @-prefixed codes in the style of preprocessor macros in C and C++. [3] Conditional compilation was introduced in IE 4, and was supported up through IE 10, in both standards and compatibility modes.
By definition, a code comment is text that is ignored by the translator – the browser, IE, in this case. But, the conditional comment feature adds syntax for a conditional statement that is formatted as a comment. Therefore, some text that is formatted as a comment is actually not a comment. It is markup code. Note that other browsers – that do not support the conditional comment feature – ignore them since they are formatted as comments.
An HTML code comment is text that starts with <!-- and ends with -->. An IE conditional comment is delimited the same, but is like:
<!--[if expression]> ... <![endif]-->
The conditional comment has two forms. The one above is called downlevel hidden. The other form, called downlevel revealed, is not formatted as a comment yet is called a conditional comment none-the-less. It is formatted like:
<![if expression]> ... <![endif]>
The code between the if and endif markup can be any HTML content that is included if the condition evaluates true or excluded otherwise.
An expression can contain the name of a feature, literal values and comparison operators. Feature names include:
Literal values are either numeric or Boolean (true/false).
Comparison operators are:
A downlevel-hidden conditional comment that includes code for IE version 8:
<!--[if IE 8]><link href="ie8only.css" rel="stylesheet"><![endif]-->A downlevel-hidden conditional comment that includes code for IE version 7 and less:
<!--[if lte IE 7]><style type="text/css">/* CSS here */</style><![endif]-->A downlevel-revealed conditional comment (which is not an HTML comment despite the name) that includes code if the browser is not IE.
<![if !IE]><linkhref="non-ie.css"rel="stylesheet"><![endif]>Microsoft acknowledges this syntax is not standardized markup, [4] intending these tags to be overlooked by other browsers and expose the content in the middle. In order to ensure compliance with W3C standards, some web developers use an alternative technique [5] for downlevel-revealed conditional comments:
<!--[if !IE]>--><linkhref="non-ie.css"rel="stylesheet"><!--<![endif]-->While possibly confusing, this syntax is valid (X)HTML and is useful for conditional sections intended specifically for non-IE browsers; if the condition evaluates to true (for example, if targeting non-IE browsers and on some versions of IE), IE displays the --> present before the HTML content. This problem is resolved by prepending <! to the initial --> as follows:
<!--[if gt IE 6]><!--> This code displays on non-IE browsers and on IE 7 or higher. <!--<![endif]-->The extra <! is ignored by non-IE browsers, and also by IE regardless of the condition. If false, everything within the conditional comment is ignored. If true, the resulting tag <!--> is unrecognized and therefore ignored.
IE 4 introduced a similar mechanism for JScript, called conditional compilation [6] that was dropped in version 11 standards mode. [7]
Example code:
<script>/*@cc_on document.write("You are using IE4 or higher");@*/</script>