DevLab

Sass Variables vs. CSS Custom Properties

Should you use Sass $variables or native CSS custom properties (--vars)? The answer depends on when you need the values resolved.

A

Sass Variables ($var)

Pros
  • Resolved at compile time — zero runtime cost
  • Work in any CSS context (selectors, media queries, calc arguments)
  • Full programming features (loops, conditionals, functions)
  • Decades of ecosystem maturity
Cons
  • Require a build step — cannot change at runtime
  • Cannot be updated via JavaScript or user interaction
  • Dead code in the output if variables are unused
  • Sass is an additional dependency to maintain
BEST FOR
Design tokens that never change at runtime, media query breakpoints, colour math, generating utility classes, build-time theming
B

CSS Custom Properties (--var)

Pros
  • Live in the browser — can be changed at runtime via JavaScript
  • Cascade and inherit like any CSS property
  • No build step required — pure CSS
  • Ideal for theming (dark mode, user preferences)
Cons
  • Cannot be used in media query definitions
  • No compile-time math (though calc() works at runtime)
  • Slightly harder to debug (computed value differs from authored value)
  • Older browser support (IE11 does not support them)
BEST FOR
Runtime theming (dark/light mode), component-scoped styling, values that JavaScript needs to read or write, design systems that ship as CSS (no build step for consumers)
Verdict

Use CSS custom properties for anything that needs to change at runtime — themes, user preferences, component variants. Use Sass variables for build-time constants like breakpoints, colour math, and generating utility classes. Most modern projects use both: Sass variables compile down to CSS custom properties, giving you the best of both worlds.

Try these tools

More Comparisons