Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is that CSS didn't include variables from the beginning (and until now)?

Tags:

variables

css

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?

like image 887
alexchenco Avatar asked Jun 22 '10 13:06

alexchenco


3 Answers

I 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.

like image 182
Omnifarious Avatar answered Oct 19 '22 17:10

Omnifarious


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.

like image 27
just somebody Avatar answered Oct 19 '22 17:10

just somebody


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.

like image 1
Alerty Avatar answered Oct 19 '22 16:10

Alerty