I've played with a lot of useful tools like HAML and LESS that gives CSS the capability of creating variables. I'm wondering why this feature wasn't included when CSS started. Is it too redundant or is not really necessary for some reason?
views:
148answers:
4I think it's because CSS wasn't really perceived as a programming language. HTML doesn't have variables either. Variables are often only seen as really necessary if you're going to manipulate them after you create them.
+1 for a good question. What you're asking for is not redundant and is certainly on the top of most CSS practitioners' wish lists (along with selector nesting).
I think this is another case of a very complicated standard that crawled to the finish line for its first release, and then, for one reason or another, it was too much effort to add certain very-nice-to-have features. The cascade itself must have been a beast for the designers to architect and browser makers to implement.
Bert Bos written up his position in Why “variables” in CSS are harmful, the other side is nicely represented by CSS Variables Are The Future.
Bos' arguments range from weak to vacuous.
Cascading Style Sheets (CSS) is not a programming language. At first, CSS was developed as a means for creating a consistent approach to providing style information for web documents. This purpose has not changed since CSS1. It is used to describe the presentation semantics of a document for certain markup languages (HTML, XHTML, XML, etc.).
What is great is that it is possible to create variables! One approach would be to use a server side language such as PHP and create some 'dynamic CSS'. Now there are several ways of doing so and here are some sites about that...
- http://davidwalsh.name/css-variables-php-dynamic
- http://net.tutsplus.com/tutorials/html-css-techniques/how-to-add-variables-to-your-css-files/
I find it useful to use 'dynamic CSS'. Here are a few examples: you can allow users of a site to change certain aspects of it such as font-size, you can change the style of the site even more easily, you can offer different style themes for a site, etc. The possibilities are endless.