Internet Explorer Mini Site

Internet Explorer Mini Site

  1. Internet Explorer Landing Page
  2. Your Internet Explorer Version
  3. Internet Explorer Problems
  4. Internet Explorer Solutions
  5. Firefox for the Internet Explorer User
  6. Make Internet Explorer render XHTML
  7. Choosing a Browser
  8. Download a Browser
  9. Frequently Asked Questions
  10. How the Internet Explorer Landing Page works
  11. How the Internet Explorer Version Detection works

Conditional Comments

Internet Explorer

Microsoft Internet Explorer supports conditional comments. These are conditions, buried in HTML comments, that allow to display content depending on the version of Internet Explorer. The simplest use of this feature is to show one thing in web browsers, and another in Internet Explorer.

the official technique

According to Microsoft, this is how you do that:

<!--[if IE]>
You are using Internet Explorer.

<![if !IE]>
You are not using Internet Explorer.

The first text is inside a comment (started by <--, ended by -->), so real web browsers will ignore it. Internet Explorer version 5 and later will recognise the conditional comments ([if IE] and [endif]) and display the text.

The second text is not inside a comment, so a web browser will display it. Internet Explorer will recognise the conditional comments ([if !IE] and [endif]) , and not display the text.

the problem

Browsers will not display the line above or the line below the text, but that does not imply everything is fine. Everything is not fine. The problem with Microsoft’s approach is that these two lines do not validate.
Microsoft’s approach does not only allow your pages to look different in Internet Explorer than they do in web browsers, but also makes your web pages invalid. That is not acceptable.

I tried the obvious solution: changing both lines into valid comments.

<!--[if IE]>
You are using Internet Explorer.

<!--[if !IE]-->
You are not using Internet Explorer.

Alas, this does not work as intended. It works fine in a browser, but Internet Explorer will show both lines and the two comments, like this:

You are using Internet Explorer. <!--[if !IE]--> You are not using Internet Explorer. <!--[endif]-->

The above code shows the logical approach. That it does not work as intended is definitely yet another Internet Explorer design mistake, but knowing whom to blame does not solve the problem.


The solution is to embed each part of the isn’t-IE condition inside an is-IE condition, like this:

<!--[if IE]> <![if !IE]> <![endif]-->
You are not using Internet Explorer.
<!--[if IE]> <![endif]> <![endif]-->

'This code complies with both web standard and Microsoft’s rules for conditional comments. It uses nothing but standards-complaint and Microsoft-approved conditional comments. The trick is that it wraps both parts of Microsoft’s ill-formed negative condition inside a well-formed positive condition. That way, only Internet Explorer gets to see the negative condition. Real web browsers see nothing but two valid comments.