Without Answers

Semantics explained. Written by Honza Sládek.

August 29, 2009 at 9:24pm

home

Does CSS Needs Variables, Selector Blocks Or Similar Stuff?

For a better part of my (short) life I was convinced it does. But lately I can’t help myself not to think that it would make more mess then good.

About a month ago Jeffrey Zeldman published an article “Why Standards Fail”. Among other things he shows there how CSS become so popular. It evolved from a really simple set of rules, which made your web pages look so much better, into an giant and complex standard which, without a doubt, is CSS 3.

To quote Jeffrey Zeldman:

"If CSS had initially offered the power, depth, and complexity that CSS 3 promises, we would still be designing with tables or Flash. Even assuming a browser had existed that could demonstrate the power of CSS 3, the complexity of the specification would have daunted everyone but Eric Meyer, had CSS 1 not come out of the gate first."

So CSS was made simple, without variables or similar things, and it’s popularity shows it was probably a good decision. CSS 2 and 3 slowly adds more control over typography, layouts etc. And all of that I can choose to use right now because it’s nicely backward compatible - if older browser doesn’t now a property it simply ignores it. Therefore any visitor can read my site, only in modern browsers the site will look a little bit nicer. But who cares if he finds information he needs, right?

And now imagine that we would add variables and nesting to CSS. I would suddenly have a pretty hard choice - to use them and forget older browsers (Or detect them and serve them different stylesheet, which I’m against, so I’m not going to do it. And it’s 2 times that much work.) or not to use them and wait till the old browsers disappear. I would say that most of the people would choose not to use them. So now we would have in CSS something nobody uses and it pretty complicates the language. But shouldn’t we do it for the future?

I simply don’t think so. Why?

  1. We can always use something like LESS. Something that will compile my own syntax which suits me to classic CSS file.
  2. I’m not convinced that we need something like that. Sure selector blocks like those Eric Meyer proposed might be useful. As well as variables. But I’m much more into writing compiling programs than adding more complexity to already complex specification.
  3. When we could add it now to the spec (which we can’t and it would take many years) and browsers would add support into their next version (let’s say it would take about a year) we would have to wait about six years for old browser to leave the market so we would be able to use our new cool selector blocks or variables. 7 years from now. Wow. Will anyone who wants to add those things to CSS now interested in them after so long?

And what do you think? Would you use variables or selector blocks or other similar things? Please comment!

And if you’re interested in using variables and selector blocks in CSS be sure not to miss my next article in which I’ll be talking about LESS and how it allows you to use variables and selector blocks. This was just a small theoretical introduction, hopefully it wasn’t too boring. :)

Notes

  1. withoutanswers posted this