IE Conditional Comments

So, I’m a bit behind the times, but this week, as I was struggling with IE box model bugs for a site I’m creating, I came across Internet Explorer’s conditional comments feature for the first time.

For anyone not familiar with conditional comments (like I say, maybe it’s just me, but I doubt it), they enable HTML to be displayed only to IE – because the code is “hidden” within a comment, other browsers ignore it.

The primary use for web designers is that they enable different style sheets to be loaded based on the version of IE a visitor is using to browse your site.

You can set conditional comments to load a different style sheet for IE5.0, IE5.5, and IE6.

The thing I like about them is that you can use them as an alternative to, say, the box model hack and let your main stylesheet take care of the rest of your styles.

So it’s not as if you end up having to maintain multiple stylesheets.

I must say that I was pretty impressed by how easy they are to use, and although I didn’t, in the end, use them for the site I’m currently developing, I will certainly bear them in mind for the future.

Quirksmode has a good write up about conditional comments for anyone wishing to learn more.

Update: Conditional comments are more popular than I thought. A recent article on A List Apart – CSS Drop Shadows II – uses them as well.