Why doesn't CSS support constants?
Posted
by
Adiel Mittmann
on Stack Overflow
See other posts from Stack Overflow
or by Adiel Mittmann
Published on 2012-03-25T17:21:36Z
Indexed on
2012/03/25
17:29 UTC
Read the original article
Hit count: 250
CSS has never supported constants or variables directly. Whenever I'm writing code like this:
span.class1 {
color: #377fb6;
}
div.class2 {
border: solid 1px #377fb6; /* Repeated color */
}
I wonder why such a seemingly simple feature has never made it into the standard. What could be hard about implementing a scheme whereby we could avoid repetition, something like this:
$theme_color1: #377fb6;
span.class1 {
color: $theme_color1;
}
div.class2 {
border: solid 1px $theme_color1;
}
I know there are workarounds, like using a class for each color or generating CSS code from templates, but my question is: given that CSS is so rich and complex, why weren't CSS constants ever introduced?
© Stack Overflow or respective owner