Don’t use CSS hacks or conditional stylesheets? Really?
Well, no, not really. Sitepoint ran an article written by Craig Buckler titled 5 Reasons to Avoid CSS Hacks and Conditional Stylesheets which caused a bit of a commotion since those methods are very popular to work around certain limitations in Internet Explorer. I mean, let’s be honest, the only reason we talk about these things is that damn buggy Internet Explorer 6. Those affect the way sites look.
The reasons:
- CSS validation may not be possible
- Your CSS becomes more complex
- Your CSS may not be future-proofed
- It is browser detection
- There is rarely a need for them
In general I agree with the reasons although I have a bit of a problem with number 3, I mean… what is ever future-proofed? And number 1 is a problem for hacks, not conditional stylesheets, but this doesn’t mean that you should say never ever jamais to the use of conditional stylesheets or even hacks. Just as there are good reasons not to use them, there are good reasons to use them and there will be times when you just have to do it. No matter how well planned and thought out the layout is, something strange can slither out of IE that is just best handled through a conditional stylesheet. Hacks not so much. I would leave those as an absolute last resort.
However, the truth is that over reliance on these tricks of the trade is not a good thing. It’s much better to plan your layout before hand, work the css out in strict mode and try alternatives instead of jumping right on to the conditional stylesheets at the first sign of trouble. Of course, practice makes perfect and it will be only through experimentation that you will learn the pitfalls of IE and css coding and the techniques to avoid them. Working with a javascript framework and some kind of css reset can also help to pave over the holes.
My personal experience has been that a site can be built with minimal code in the conditional stylesheets, sometimes just a couple of lines, and in some special cases with none. And most of the time hacks are not needed at all. A lot of the problems can be avoided if we manage client expectations by warning them that trying to make the site behave exactly the same in IE6 as it would in Firefox, Safari or IE7 may mean bending over backwards or cutting back on features for high-end browsers. This doesn’t mean we shouldn’t build a good experience in IE6.
So, do I agree with the Sitepoint article? Yes. Those there are valid reasons to keep in mind. It doesn’t say there that you should never do it, it all comes down to analyze the layout, evaluate the options and decide on the better solution instead of taking what looks like the easy way out every time.



