CSS hacks and server-side code

Scott Isaacs, one of the Microsoft web chaps, is complaining about CSS hacks. His proposed solution is to, instead of applying CSS hacks to make a browser do what you want, instead have details of the users browser inserted into the HTML element either by server-side or client-side script. So, if you visit a page using IE6.0, it would add class="ie m6 d0 win" to the HTML element; using Firefox 1.06 on Linux it would add class="firefox m1 d06 linux", and so on. Then, in your stylesheet, use these hooks to apply style for specific browsers.
I think that this is not a good idea, and here’s why.
Firstly, it requires absolutely that every page be server-parsed, since you can’t rely on client-side scripting being there. Well, unless you’re prepared to make your styling depend on JavaScript, which rather defeats the point of CSS. In some places it seems like the norm is to make all pages, even ones with plain HTML and no dynamic content at all, be server-parsed by making them ASP or PHP, but I don’t like to do that for pages that don’t need it. If you’re thinking “but every page needs a header and that’s normally dynamically included!“, think about automatically generated pages which are generated dynamically when required and then cached, like blog archives. Or think about mailing list archives, or pages where the header and footer are added by your web editing tool like Frontpage or Dreamweaver rather than by the server.
Secondly, it clutters the HTML a bit. Not much, but a bit. This isn’t much of an objection.
Thirdly, how do you establish the platform and short-name-for-a-browser and major and minor versions? Parse the userAgent string? That takes us back to the days of browscap.ini and The World’s Biggest List Of Browsers, which you have to rely on someone to maintain.
In short, I don’t like the idea. I’d be interested in hearing dissenting opinions, though.

(Incidentally, you may be thinking that this should have been a comment over at Scott’s rather than a post here: I agree with you, but to post there you need an MSN passport and I don’t want to get one.)

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)