Why doesn't CSS support constants?
- by Adiel Mittmann
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?