CSS Variables Analysis
August 5th, 2008
I’ve read an essay about CSS variables intitled Why “variables” in CSS are harmful, where the author presents his toughs on the harmfulness of CSS variables. Here’s a quote:
Somebody who reads a style sheet with symbolic constants has the same problem as the author reading his own style sheet after not looking at it for some time, only worse. The author may manage to remember the function of some name after a few hints, any other person will have to hypothesize and check the function fully from what is written in the style sheet itself.
The main argument is that variables would make CSS less readable, because someone could create a variable with an improper name, and later on it would be difficult to know the purpose of the variable just by looking at it.
But that isn’t a CSS variable problem, is a global variable problem that we have on almost every programming language. It’s the programmer’s job to write clean, quantity, maintainable code. It shouldn’t be the language forcing restrictions. Furthermore, CSS isn’t known by its maintainability. We all know one or two style sheets that are so big, that they become very hard to maintain. And I really don’t know many ways to properly organize CSS code.
My opinion is that CSS global variables would be useful. Having a couple of variables with the colors of the site, for example, would really increase the file maintainability, because in the event of changing one color, we could just adjust the variable, instead of a major find and replace…
Although I don’t particularly agree with the author on several topics Why “variables” in CSS are harmful is an interesting read.
Related Posts
- Orion's Belt AI
- The NHibernate FAQ Blog
- LinkedIn Mayhem
- Wikipedia on a Rampage
- Running Mono - an Overview




August 5th, 2008 at 10:02 am
I agree with the overall tone of the article (haven’t actually read it through). If it’s something built into in the language, something like this will certainly be misused. Just like !important was/is.
Another thing is.. if you reaaaaaally want to use this, code your own solution.
It’s not that hard. If you want to serve static files, write a compiler that minifies the CSS and also replaces the constants by the values you want. If not, just write a script that does this on-request.
I would much rather see qualified selectors [1] added to the spec than this css variables nonsense.
[1] http://www.shauninman.com/archive/2008/05/05/css_qualified_selectors
August 5th, 2008 at 10:08 am
Hey André,
I actually have my own solution, built with velocity. I agree that one could just write a facade, but in my opinion this is the kind of utility that could become standard.
Certainly, it isn’t as important as the qualified selectors.
May 28th, 2010 at 1:06 pm
DreamWeaver — PageMaker for the Web — sees the page as a bunch of boxes. It thinks in tags, translates to numbered s, and puts it all into the .