Conditional Comments

By Deane Barker on April 27, 2004

About Conditional Comments: A handy but pretty obscure feature of Internet Explorer. A special comment format lets only IE see certain HTML / CSS code. So make that Web page look good in Mozilla and Opera, then hide the code necessary for IE in these comments.

Conditional comments have certain advantages over scripting methods of browser detection. When a downlevel browser encounters a downlevel-hidden conditional comment, the browser does not see the inner HTML inside the comment, and the content elements are not downloaded and rendered. This saves both bandwidth and machine resources.

I had never heard of this until Joe showed it to me one day. It’s kludge, sure, but it’s endorsed kludge and it really is handy.



Comments are closed. If you have something you really want to say, tweet @gadgetopia.