What are Conditional Comments?

Well I bought the domain name, so I should probably explain.

All programming languages have the concept of a comment. Programmers use them to leave messages to themselves or other developers to help understand what a certain piece of code actually does.

In languages like Java or PHP you can use two forward slashes and in HTML they take the form of <!– Comment goes here –>

So that is comments. What is a conditional comment?

Well, in a nutshell they are a special type of comment that sends code just to Internet Explorer. The reason we might want to do this is due to perhaps one of the biggest frustrations a web developer faces on a daily basis.

Internet Explorer is and has been for a long time the most popular and most widely used web browser there is, but older versions of it do not display websites as they should.

To get around these bugs in older version of internet explorer we use conditional comments to “fix” our code in that particular browser.

for instance, if I find something doesn’t work in internet explorer 6, I put some code in to fix it. But to make sure that code doesn’t break other browsers, I make a condition that only IE6 will use it.

<!--[if IE 6]>
Special code for IE 6 here

The first line is the condition, (if the version of IE is 6) and then inside it we put our fix.

For more information have a look at the wikipedia article about them


  1. nick says:

    Here is a comment

  2. Lou Parnell says:

    Very neat article post.Really looking forward to read more. Cool.

Leave a Reply