Taking Conditional Comments Too Far

I’ve come to accept and support conditional comments as a tool to use when it’s otherwise impossible to get Internet Explorer to behave desirably. To me, they’re much more acceptable than unstable CSS hacks or extensive !important declarations. They’re much easier to maintain, and it’s the only truly reliable way to target not only Internet Explorer itself, but specify a version as well. The subject of conditional comments comes with great debate that seems to be ongoing. There are good arguments on both sides, but to me, conditional comments seem like the best solution.

When I use conditional comments

Up until this point, conditional comments have saved the day for me simply by being present in the head of my documents. For nearly every client project, I find myself using conditional comments to target both Internet Explorer 6 as well as Internet Explorer 7. In my opinion, as far as standards compliance is concerned, IE7 is merely a shuffle forward, as opposed to a step.

I’ve also accepted using conditional comments to include JavaScript written specifically to assist Internet Explorer. A specific example that comes to mind is when I’m implementing Suckerfish Dropdowns. I elect to include the JavaScript with a conditional comment simply because the script is only meant to be run when browsing the document in Internet Explorer 6. I prefer to have other browsers ignore the JavaScript for simplicity’s sake. While it may not be considered harmful to allow JavaScript such as the bit needed for Suckerfish Dropdowns in all browsers, to me it is settling to keep it separated.

Using conditional comments in the body

Until recently, it hadn’t even occurred to me that using conditional comments in the body of your document could become commonplace. There’s no documentation specifying that conditional comments can be used only in the head of your document, so why stop there? To me, using conditional comments in the body of your document is partially counter productive.

The reason I choose to employ conditional comments is their nature of providing longevity. By writing specific style sheets to target specific versions of Internet Explorer, I’m able to solve a rendering issue and leave the solution as is for the life of the document. The problem is solved with a minimal change to the DOM.

When you choose to use conditional comments in the body of your document, you’re electing to alter the DOM in a more significant way. Now, instead of working with different style sheets to solve a problem, you’re altering the problem itself. If this route is chosen, you now have a number of choices. You can alter a significant portion of the DOM in order to work with a single, existing style sheet, or you can take both sides and use conditional comments to include Internet Explorer specific style sheets as well as alter the DOM at the same time.

The idea in general, to me, seems more sloppy than resorting to the use of CSS hacks strewn throughout your document style sheet. Your source will become ugly and awkward to maintain, and the longevity of your document will be greatly reduced. Using conditional comments to include a version specific style sheet (or a bit of JavaScript) should be all the ammo you need to solve the problem of Internet Explorer.

What’s your opinion?

How do you feel about conditional comments in the first place? If you’re opposed, is it due to the fact that the code is technically proprietary? Is it due to the fact that the implementations you’ve seen are as outlined above in that conditional comments are littered across the entire DOM?