Andrew Jaswa

Un-Conditional

Conditional comments. Browser hacks. You might like them, but I don’t.

Why don’t I? Mainly because they present a unique set of instructions to one or many browsers but usually not to all of them at the same time. So what big deal? Right? I mean we’ve done that for years why, should we stop coding and presenting things for a particular browser?

Browser Hacks

You can do some pretty neat things with sending one set of instructions to one browser and another set to a different one. Take a look at the CSS Zen Garden design Gemination. It is presented as one design to IE and another design to the other major browsers. This uses CSS to set styles for one browser then over writes them for another browser. Now while this isn’t conditional comments, it still follows the same idea: one set of instructions is being sent to one browser and a different set for another.

Conditional Comments

Conditional comments are Microsoft’s way to target different versions of Internet Explorer. Jens Meiert presents rather strong arguments as to why conditional comments are bad. I won’t get into that side of things he does, but there is another side. This other side is what I call conditional CSS.

Conditional CSS

Do you ever run into a website that requires you to use a specific browser? I’m talking recently, not 10 years ago. Well I have… It wasn’t pretty. The web has grown up lately (in case you haven’t noticed) and browsers are getting better at rendering things. There is no longer a need for Internet Explorer or Firefox only websites.

Conditional Comments are mainly used for CSS. Browser hacks are based on the differences in the support of CSS by a specific rendering engine. A combination of conditional comments and browsers hacks is what I like to call conditional CSS (cCSS). cCSS is a way for you to deliver different instructions to different browsers. You shouldn’t ever need to do this. Browsers are now at a point where they’ve started to render things very closely the same. If you continue to use cCSS at some point in time it will begin to break sites that you’ve built in specific browsers.

Pixel perfection

One reason that people use cCSS is to make websites looks exactly the same in all the major browsers. Well they don’t need to be. I realize that this might be in contradiction from what I was just saying but hear me out. By not using cCSS you’ve ensured that your site will be more future compatible than ones with hacks. You’ve also removed the need for extra CSS that adds file weight. Think about this: do you want to download an extra CSS file for each browser only if you are using just one?

cCSS comes down to this: it’s an un-elegant way to produce websites. You should be able to build out sites with very little hacks and conditions. Be un-conditional. Take out your cCSS and start building better more standard websites.

June 2, 2008

4 Comments »

  1. Good article. Problems are so well documented, that there are always easy ways (with the exception of poorly written legacy systems) to get around using cCSS.

    What always irks me is that (x)HTML is a markup language, not a ‘programming language.’ By using cCSS, you are ignoring the distinction. Use JS/PHP (or other server side language) for programming. Use CSS for styling. Use XHTML for markup.

    Comment by Zach Young — June 4, 2008 @ 4:02 pm

  2. Andrew, your post is so extremely close to being true, it seems petty and nitpicky to disagree, but you’re presenting statements in sweepingly absolute terms… but %99.95 percent right isn’t totally right…

    There’s exceptions for almost everything you’ve said.
    Consider… A designer is in a shop that is stuck with legacy code where all pages are delivered in Quirks mode and management cannot be persuaded to overhaul and modernize the spaghetti code that controls thousands of sites… in which case you MUST address the wildly different concerns of browsers with some mechanism to send different rules to different browsers.

    Or, even in Standards mode, IE still has nearly a third of the market share, and it can’t handle PNG alpha transparency… due to the slicing the graphics team has done, with some curious overlay effects, transparency is essential, either a GIF needs to be served to IE6… or scripting will be necessary to call in IE’s proprietary (horrors!) non-standard filter property.

    “If you continue to use cCSS at some point in time it will begin to break sites that you’ve built in specific browsers.”

    An absolutist statement! Anyone who does that carelessly runs an extremely high risk of breakage, but if one’s conditional CSS is targeted say to versions < IE8 via conditional comments, it’s almost certain not to break, but just fade away as IE6 and 7 do.

    That said, everything you wrote is dead-on right IN PRINCIPLE… Barring the exceptions of legacy shops, having to work with certain peculiar files, etc, or the agony of being trapped in a Quirks mode environment, your statements hold true, but there are thousands of coders out there who are working in very suboptimal conditions due to circumstances beyond their control. At least until IE 6 and 7 give a well-deserved kick to their respective buckets, those guys will be addressing the needs of their jobs as best they can.

    Comment by Jon Zuck — June 4, 2008 @ 11:15 pm

  3. Jon, you are absolutely right, there are exceptions to nearly everything I wrote. All your criticisms are dead on and well founded. However, I was being absolutist for a reason. If one can’t set high goals, then they will never reach their greatest potential. The point being if you never try you won’t succeed. I would suggest that anyone that falls into the exceptions you wrote about, should try to no longer be the exception. I might go as far as saying that the developers have a responsibly to their company to produce the best product they can. If it so happens that early shipping a bad product is the norm, then that is larger problem in the company. In less words, no one should settle for a sub-standard product.

    Comment by ajaswa — June 7, 2008 @ 3:14 pm

  4. You’re an inspiration!
    I dub thee Sir Andrew, Lord of Standards!

    Your Humble and Most Unworthy Servant,

    Jon, shedding the slime of three years of forced Quirksmode hackery.

    Comment by Jon — June 10, 2008 @ 10:29 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

I build crappy websites every day!
Andrew Jaswa