tags:

views:

148

answers:

4

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?

+2  A: 

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.

Omnifarious
I agree. CSS has been really simple, and accessible to the majority of people. Although now I see it turning into more of a programming language, since CSS introduced it's first interactive classes. Something as simple as :hover is going to get much more functionality with CSS transitions and such.As much as I enjoy it, I think HTML and CSS should be kept as the design layout layer, and a separate language (javascript) should be used for interactions on a webpage.
danixd
@danixd: I agree, for the most part. Is it possible to embed JavaScript in a style sheet, though? Because I can see how that could have some potential usefulness.
JAB
@JAB: In fact, it is best not to mix JavaScript and CSS. JavaScript can be disabled on a user's browser and that would mean a broken style for the site... a very ugly mess. On the other hand, you can use a server side language such as PHP for that (have a look at my answer).
Alerty
@Alerty: Oh, right. Forgot about that aspect of JavaScript.
JAB
@Alerty, CSS can be turned off too
Malfist
@Malfist: And that would create an even bigger mess ;)
Alerty
@Malfist: Actually, I am rather impressed that it is possible to turn CSS off. CSS does not represent a security risk in any way (that I am aware of) because it is a style sheet and has nothing to do with programming language.
Alerty
It's for accessibility that it's able to be turned off. You can actually specify css in the browser that will override anything on the page. Back when I was reading a lot of stuff online for classes, I'd override page colors to make it look more like the Zenburn theme which is a lot easier on your eyes.
Malfist
A: 

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

Robusto
+1  A: 

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.

just somebody
"# number of CSS style sheets: 25725", "# number of non-empty style sheets: 24805" Is there any purpose to those 920 empty style sheets?
JAB
+1 for the links and the use of the word "vacuous"
Malfist
no. have you never seen a careless programmer remove the last remaining few lines from a file and leave the file instead of removing it altogether? ;)
just somebody
@JAB It means he's using a non-representative sample.
Malfist
+2  A: 

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

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.

Alerty