Using CSS hacks is just plain stupid
The Web Standards movement has created a ‘culture of hacks’ to compensate for browser incompatibilities (OK, mostly IE) and this is a bad idea.
Before anyone attempts to tell me that the Web Standards community does not promote the use of hacks, please refer to just about every book written on Web Standards based web design.
Why were hacks promoted?
In a nutshell: those who promoted them are inexperienced … in other words: green. It is simply bad practice to rely on broken aspects of a technology in an attempt to make things work – any programmer worth his salt knows this. And that is exactly what many/most hacks rely on – broken aspects of Internet Explorer.
-
Anecdote: I’ve often had to ’slap-down’ young-pup programmers (just a few years out of school,) when they’ve tried to introduce into the code base, what would be the equivalent of CSS hacks.
-
CSS hacks are a recipe for disaster that I’ve been predicting for a while, a disaster that seems to be happening: it looks as though IE7 will be breaking CSS hacks and thus, the Web Standards myth of forward compatibility.
I’ve used a hack: I’m a god-curse hypocrite:
Yes, I’m guilty of ‘following the pack’ and I’ve used a single CSS hack (child of div hack) but I used it in a minimal way – should the hack fail (and it will in IE7,) my layouts will still work though the pixels will shift a little.
The real problem occurs when you start using many hacks or if your hacks should fail, your website’s usability will be severely compromised.
If you have to use hacks, use them very delicately.
The hack-free cross browser compatible solution:
When you’re critical of something, you should try to present alternatives … and my alternative to using brittle CSS hacks:
Use a IE conditional comments, Microsoft intelligent solution to cross browser coding.
I know, I know … Microsoft coming up with an intelligent solution!?
Stefan Mischook (a.k.a: The Web Design Heretic )
February 7th, 2006 at 7:52 pm
[..]CSS hacks are a recipe for disaster that I’ve been predicting for a while, a disaster that seems to be happening: it looks as though IE7 will be breaking CSS hacks and thus, the Web Standards myth of forward compatibility.[..]
Web standards and CSS hacks are 2 different things.
[..]the Web Standards myth of forward compatibility.[..]
My CSS based site looks great on the PSP and on the new mobile phones and my older table based websites look horrible on these newer generation devices.
February 10th, 2006 at 12:00 pm
“My CSS based site looks great on the PSP and on the new mobile phones and my older table based websites look horrible on these newer generation devices. ”
-
No doubt. But many websites don’t need to look good on PSP or mobile phones. You have to think about how these new devices will be used on the web.
…
I doubt people will be surfing with their cell phones to read articles – it’s just too small. But, if my website was giving out stock quotes, I can see where I want to have an interface for cell users.
February 12th, 2007 at 12:59 pm
[...] My beef is that CSS hacks are just a bad idea, and Meyer uses his hacks all over his books … [...]
November 7th, 2007 at 4:44 pm
Hacks are not evil. It depends on what you’re working on. They can be quite helpful. If you’re making a site to stand the test of time, you might want to stay away from hacks. When new browser versions come out, as stated in this article, the hacks will break. But if you’re working on sites with a short lifespan (less than a year) and have to make your sites look virtually the same in 3 different browsers– hack away. (That is, if you are restricted from using javascript for cross browser scripting.
The point I am making, for the working coder with one arm tied behind his back–hacks are a very dear friend!