There’s so much great stuff written about web standards available for free on the web that it’s easy to forget how much bad stuff is also out there; and how many people are willing to support it just because it’s easier than putting in a little extra effort to follow best practice.
Over the weekend one of the most popular stories on Delicious.com was teaching the use of lazy CSS hacks, the type of which I thought everybody was convinced enough to do away with; the star and underscore hacks for targeting IE6 & IE7, the hacks which we’ve been saying (for years) shouldn’t be used anymore.
Disregarding the ‘rights’ and ‘wrongs’, and the validation argument — some of my stylesheets don’t validate, and there are good reasons for that — I’d like to give a few other reasons why using this method is not a good idea.
First and foremost, maintainability; separating out the rules for outdated browsers with conditional comments leaves your standards‐compliant stylesheets clean and easy to manage; you don’t have to wade through multiple rules looking for the ones you need. IE6 & IE7 styles are safely out of sight.
Second, and one of the core arguments for not using hacks, is future‐proofing; using a hack like this in the main stylesheet could lead to a situation in the future where a new browser — or new version of a current browser — could render this hack incorrectly. It may not be likely, but can you guarantee no future browser will not render strangely when interpreting these rules?
As well as practical reasons not to use hacks, there is one good moral reason: to not be lazy. Writing the syntax for conditional comments takes less than a minute, and while using hacks means there is some reduction in the number of characters required, complex stylesheets can contain dozens — or even hundreds — of rules, and adding those hacks for each rule will mean you end up using almost as many characters as you would with conditional comments.
It’s pretty disheartening to see comments that suggest standards are just for people who want to sell books or conference tickets; standards are to make the jobs of web developers easier. Even the lazy and bone‐headed ones.