Skip to content
CSS·Intermediate·Coding·1 min read

How does a CSS custom property differ from a Sass or LESS variable?

Short interview answer

A preprocessor variable is substituted once at compile time, producing static output CSS with no trace of the variable. A custom property is a real runtime value that participates in the cascade and inheritance; var() re-evaluates it whenever the winning declaration for that property changes, which is what lets one override restyle an entire subtree without recompiling anything.

Example

CSS
:root { --gap: 8px; }.tight { --gap: 4px; }              /* live override */.stack { gap: var(--gap); }        /* re-resolves per element */

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Custom properties and theming

Related questions