IE Conditional Comments

Internet Explorer Conditional comments are conditional statements used only by Microsoft Internet Explorer in HTML source file. It gets frustrating when different versions of Internet Explorer displays web pages differently due to the browser problems. In some situations we cant avoid Internet Explorer because of various reasons such as our visitors are still using different versions of Internet Explorer. In these situation We typically use IE conditional comments to fix the IE issues.

Internet Explorer Conditional comments

Internet Explorer Conditional comments can be used to display and hide code to and from Internet Explorer. It uses a special syntax.

IE Conditional comments

The If the statement evaluates to true, the enclosed HTML is rendered within the HTML document. If the statement evaluates to false, the enclosed HTML remains hidden from the user. Also noted that Conditional comments can be placed at any part of the HTML file at which normal comments can be located.

IE Conditional statements

Examples:

ALL VERSIONS of Internet Explorer

EXCEPT Internet Explorer

Internet Explorer 9 ONLY

Internet Explorer 8 ONLY

Internet Explorer 7 ONLY

Internet Explorer 6 ONLY

Internet Explorer 5 ONLY

Internet Explorer 7 or Below

Internet Explorer 6 or Greater

Not Internet Explorer 6

You can use operators within your expressions

Internet Explorer 6 or 7 only

greater than IE4 and less than IE7

This one use in the case of IE5 and IE6.

Conditional comments in JScript

example

Detect Internet Explorer version using JScript

You can use corresponding conditions in Cascade Style Sheets (CSS) also.

Some samples are given below

All browsers

Internet Explorer 7 and aabove

Internet Explorer 6 only

Internet Explorer 5.5 only