Safe CSS Hacking

In a time when some web developers are trying their hardest to make standards compliant websites using proper CSS and XHTML, far too many hacks have come about to solve a plethora of problems in design. Most of these hacks are, in my view, extremely unnecessary.

In fact, I would take that a step further and say that if you have to fill your code with a million hacks for it to work well in IE, Opera, Safari, and FF … then you are not coding it well to begin with. There are a few hacks that have true use and purpose, but as so many people have seen with the advent of IE7, there is always the concern that many hacks will later be rendered useless by browser versioning and require a replacement (free of charge from the web developer, of course).

Is it truly worth that to developers to hack their sites? To watch their websites stumble and break upon the creation of a new browser version, only to have to go back later and make changes for all their old client websites at no cost? Or is it just easier to code it right the first time and avoid doing things that would even need a hack? There is always more than one way to do something.

I’m certainly an advocate of standard coding methodologies, but it defeats the purpose of using standard code if you have to hack your own code constantly. I can absolutely say without question that I have made websites that are perfectly functional in various browsers without using hacks. I have made sites fully backward compatible that only involved hacks for browsers no longer being changed – and that is what I would suggest to anyone else.

Mantra: Only use hacks for things what will never change.

Well, what will never change? Netscape 4, and IE 5 for Mac’s, and IE 5.5 for instance. Microsoft has completely dropped support and development for them, so you are safe using hacks for those browsers – they will never change. According to Microsoft they will still maintain updates occasionally for IE 5 on Windows because it was packaged with Windows 2000.

Things like the common @import hack to hide things from Netscape 4 are fine, but there really is no reason to (and plenty of reasons not to) use hacks for browsers that are still updated. On the other hand, using conditional comments is not something I’d consider a hack because it is an accepted feature. In fact, if you are going to use hacks on a website for IE, your best bet is to use conditional comments (ex: <!–[if IE 6]>).

Overall, the most important thing to keep in mind is that you do not want your website hacks to break just because a new browser comes out. Therefore, keep your hacks only in the realm of browsers that are no longer supported and developed. It will save you a lot of stress in the long run.