Conditional Comments

Whoa. I just learned about Internet Explorer’s conditional comments feature. If you need some HTML code to be parsed only by IE (or even particular versions thereof), this is the way to do it.

Here’s a basic example of a “downlevel hidden” conditional comment:

<!--[if IE]><style type="text/css">
  /* these CSS rules will only be visible to IE */
</style><![endif]-->

“Downlevel hidden” comments are syntactically valid HTML comments, so they will be ignored by “downlevel” (that is, non-IE) browers. There are also “downlevel visible” comments which are visible by default, but your HTML won’t validate if you use them:

<![if condition]>...<![endif]>

However, the “downlevel hidden” variety are quite sufficient for applying IE-specific fixups, which is probably all you’ll really care about unless you want to add a “better viewed in IE” message to your web page.

hoodwink.d enhanced