13
Yesterday, I mentioned that I love CSS variables. Today, I thought I’d explain what they are and how they work, for those who aren’t already familiar with them.
Let’s dig in!
How to define CSS variables You define a CSS variable by typing its name with a leading double-dash (--).
It uses the same syntax a typical CSS property—--{name}: {value}—and must be defined on an element.
p { --size: 1rem; } You can then use your CSS variable just like you would any other property value by wrapping it in var().
It has variables as well as modules, easily nestable definitions, and inheritance so that you can have base classes
CSS has variables, modules and nesting.
By inheritance, do you mean the
extends
keyword? Because if so, it just seems like going further down the misguided BEM path instead of picking better selectors.