Full answer
A custom property is a value you name yourself, starting with two dashes, like --brand. You read it with var(--brand). You can give a fallback as the second argument: var(--brand, teal).
They take part in the cascade and they inherit. Declare them on :root for global values, or on any element for a local override. Every descendant sees the new value.
Sass variables are different. Sass runs at build time and replaces each variable with a fixed value, so the browser never sees them. A custom property lives in the browser, so JavaScript, media queries and class changes can change it while the page runs. That is what makes themes and component tweaks easy.
The light panel uses the root brand colour, and the dark panel overrides --brand on its own element, so its link is lighter. calc(var(--space) * 2) gives 16px padding. The undefined --missing falls back to gray.
Because the browser resolves var() at computed-value time, a custom property can hold anything, such as a whole shadow or a list of numbers, and you can change it from JavaScript with element.style.setProperty('--brand', 'tomato').
<style>
:root { --brand: #0a6cff; --space: 8px; }
.dark { --brand: #7fb2ff; --bg: #111; --fg: #eee; }
body { margin: 0; }
.panel { --bg: #fff; --fg: #111; background: var(--bg); color: var(--fg); padding: calc(var(--space) * 2); }
.panel a { color: var(--brand); }
.panel .note { color: var(--missing, gray); }
</style>
<div class="panel" id="light"><a href="#" id="l1">Light link</a> <span class="note" id="n">fallback</span></div>
<div class="panel dark" id="dark"><a href="#" id="l2">Dark link</a></div>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Custom properties start with two dashes and are read with var(--name, fallback).
- They cascade and inherit, so a class can redefine them for its subtree.
- They can change at run time, unlike Sass variables.
- var() cannot be used inside a media query condition.
- Store the unit with the value, or multiply with calc, to avoid invalid values.
Common mistakes
- using a custom property inside a media query condition. It does not work there, because var() is not valid in the query itself.
- writing --size: 10 and then width: var(--size)px. That produces an invalid value. Store the unit too, or use calc(var(--size) * 1px).
Follow-ups
- what happens when a var() has no value and no fallback?
- What does the browser do when a var() has no value and no fallback?
- How do you change a custom property from JavaScript?
Tips
- Name tokens by purpose (--color-text, --space-2) rather than by value (--blue). Renaming a colour then does not mean renaming the variable.
- Show a two-theme example in a few lines. It proves that you understand scoping.
- Name tokens by purpose such as --text and --space-2, and mention that in the answer.