CSS variables: plainly explained.

CSS variables (custom properties) store a value once and reuse it across a stylesheet. How to declare them with var(), scope, and versus Sass variables.

Design · Updated Nov 7, 2026

DEFINITION

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.

CATEGORY

Design

RELATED

Design Tokens, Design System

Summarize this page with AI

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.

01

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);
02

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.

03

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.

Aspect
ResolvedCSS variableAt runtime, in the browserSass variableAt build time
Change liveCSS variableYes (media query, JavaScript)Sass variableNo
Cascades and inheritsCSS variableYesSass variableNo
Best forCSS variableTheming, dark mode, design tokensSass variableBuild-time logic, mixins, maths
04

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.
05

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.

06

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

Questions about CSS variables.

Another question?

Write to us
What are CSS variables?
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.
What is the difference between a CSS variable and a Sass variable?
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.
How do you declare a CSS variable?
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).
Can CSS variables change at runtime?
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.
What is :root in CSS?
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.
Does Webflow support CSS variables?
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.

Related

Related terms, and where to go next.

Illustration for the article “How to find the best website designer for your project”
Development

How to find the best website designer for your project

Find the best website designer for your project with a clear evaluation framework, practical checklist, common mistakes and FAQs.

Read the article
BeBranded
UX/UI

html.to.design: import any website into Figma

html.to.design converts any website into an editable Figma design. Benchmarks, redesigns, and HTML capture for AI-assisted development.

Read the article
Illustration for the article “What a Webflow designer does beyond visual design”
Development

What a Webflow designer does beyond visual design

Learn what a Webflow designer does beyond visual design, from CMS planning and SEO setup to conversion strategy and project handoff.

Read the article

Let’s talk

Tell us what you want to build.

Thirty minutes with the people who will work on your project. You leave with a clear view of the scope, the timeline and the next steps.

What happens next

  1. 1A 30-minute callWe listen to your goals, your constraints and your context.
  2. 2A clear scopeWe map what is worth doing first, and what it takes.
  3. 3A costed proposalYou decide, with no commitment and no sales pitch.