CSS variables

CSS variables, also called custom properties, store a value once such as a colour and reuse it across a stylesheet, so you update everything from one place.
Design
Created on
23.08.2026

Summarize this

CSS variables, officially called custom properties, let you store a value once and reuse it throughout a stylesheet. Define a brand colour, a spacing step or a font family in a single place, reference it everywhere, and a change to that one declaration updates the whole site. They are the native CSS way to keep design values consistent, without a build step.

How to declare and use them

A custom property is declared with a double-dash name, usually on the :root selector so it is available everywhere, and read with the var() function. A fallback can be passed as a second argument.

  • Declare: :root { --brand: #1a1a1a; --space: 1rem; }
  • Use: color: var(--brand); padding: var(--space);
  • Fallback: color: var(--brand, #000);

Scope and the cascade

Custom properties follow the cascade and inherit like any other CSS. Declared on :root they are global; declared on a component they are scoped to that element and its children. This lets you set a default once and override it inside one section, one card or one dark block, without touching the rest of the site.

CSS variables versus Sass variables

The two look similar but work at different moments. A Sass variable is resolved once at build time and then disappears from the output. A CSS variable lives in the browser at runtime, so it can be changed with a media query or with JavaScript, which is what makes live theming possible.

AspectCSS variableSass variable
ResolvedAt runtime, in the browserAt build time
Change liveYes (media query, JavaScript)No
Cascades and inheritsYesNo
Best forTheming, dark mode, design tokensBuild-time logic, mixins, maths

Common use cases

Custom properties shine wherever a value repeats or must change as a set.

  • Design tokens: colours, spacing, radii and typography defined once and reused.
  • Dark mode: redefine a handful of properties inside a media query or a data attribute.
  • Theming: swap a brand palette per section or per client from one place.
  • JavaScript control: read and set properties with getComputedStyle and style.setProperty for interactive UI.

Best practices and pitfalls

Name properties by intent (--color-text, not --dark-grey) so the meaning survives a rebrand. Keep global tokens on :root and scope local overrides tightly. Remember that a custom property holds a plain string: it is only validated when used, so a typo fails silently, which is why a sensible var() fallback is worth adding on critical properties.

CSS variables at BeBranded

At BeBranded we drive colour, spacing and type from custom properties, so a brand can evolve from one source of truth and stay consistent across every page and component. It is part of the scalable, token-based front-end in our design work.

FAQ

CSS variables, also called custom properties, store a value once and reuse it across a stylesheet with the var() function. Changing the one declaration updates everywhere it is used.
A Sass variable is resolved at build time and then gone. A CSS variable lives in the browser at runtime, so it can change with a media query or JavaScript, which enables dark mode and live theming.
Declare it with a double-dash name, usually on :root, for example --brand: #1a1a1a. Then read it with var(--brand). An optional fallback can be given as var(--brand, #000).
Yes. Unlike preprocessor variables, custom properties exist in the browser and can be updated with a media query or JavaScript, so a single change can re-theme a whole interface.
The :root selector targets the top of the document (the html element). Declaring custom properties there makes them global, so they are available to every element on the page.
Yes. Webflow variables map to CSS custom properties, so colours, sizes and fonts defined once in the Designer can be reused and updated across the whole site.

Ready to boost your conversions?

Our team is here to understand your needs & work with you to create your next projects.
Get news, infos and resources.
Actionable tips delivered straight to your inbox.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.