Conditional Comments

Internet Explorer 5 through IE 9 supports conditional comments.

IE 10 will not support conditional comments when it sees the HTML 5 DTD, but will still work with them with other DTDs.

IE is the only browser that understands or uses conditional comments (it’s also the only one that needs to!).

What are conditional comments? How do you use them?

Basically they are comments that only IE parses that allow you to provide special HTML, CSS, & JavaScript to users of that browser. Here’s a simple example:

<!--[if IE]>
<p>You are using Internet Explorer. Please stop.</p>

The conditional comments starts & ends with standard HTML comment syntax: <!-- & -->. Every web browser except IE will see that & ignore everything inside it. IE, however, will see a comment & then keep looking. If it see the stuff in square brackets—[if IE]> & <![endif] in this example—it will use or display the code inside the comment1. It can also hide stuff instead of show, & do more than that. To learn more, start with these articles.

Start with Wikipedia (as with so many things!): Conditional comment. Explanation, examples, references.

This article, from Microsoft, does a good job explaining what they are & how to use them: About Conditional Comments.

For more info, see Conditional comments, from the great QuirksMode website.

If you'd like to see conditional comments in action on a live site that WebSanity had done, view the source code on

  1. If IE does not see code that indicates that it's dealing with a conditional comment—if the stuff, in other words, inside the square brackets is missing—then it treats the code as commented out & ignores it, just like every other web browser in the world. 

WebSanity Top Secret