# CSS Custom Properties

> Named values in CSS, like --brand, that you set once and reuse all over the page.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** CSS Variables, CSS Variable, var(), --custom-property

## Think of it like

It is like a paint pot with a name. Change the paint in the pot, and every wall changes.

## Definition

CSS custom properties are values you name once and reuse across a stylesheet. The name starts with two dashes, like --brand. You read it back with var(--brand), and you can give a backup value after a comma. Most people set them on :root, so the whole page can use them. Change one line, and every place that uses it changes too.

## Example

Emma's site uses one teal in 40 places. She makes it --brand, so a new brand colour is now a one-line change.

## Example code

```css
:root { --brand: teal; }
.button { background: var(--brand); }
.link { color: var(--brand, blue); }
```

Set it once on :root, then read it with var(). The link falls back to blue if it is missing.

## Why it matters

Themes like dark mode become easy. You swap a few values, and the whole page follows.

## Common mistake

Writing the name without var(), like color: --brand. That does nothing; you need var(--brand).

## Three principles

- **Two dashes.** Names start with --.
- **Read with var().** Add a backup after a comma.
- **They pass down.** Children get the value of their parent.

## Related terms

- [Cascading Style Sheets (CSS)](https://learn.benibix.com/term/development/css)
- [Sass](https://learn.benibix.com/term/development/sass)
- [CSS Specificity](https://learn.benibix.com/term/development/css-specificity)
- [Tailwind CSS](https://learn.benibix.com/term/development/tailwind-css)

## Told apart from

- [Sass Variables vs CSS Custom Properties](https://learn.benibix.com/compare/sass-vs-css-custom-properties): People think Sass variables and CSS custom properties are the same thing, and they are not. A Sass variable, like $brand, is used up when the Sass turns into CSS, so the browser never sees it. A custom property, like --brand, lives in the browser. Code can change it while the page runs, which is how dark mode can work.

## Taught in

- [CSS Frameworks and Sass](https://learn.benibix.com/learn/development-web/css-frameworks-and-sass): HTML, CSS and JS, 11/14

![Three panels. Custom properties: one line on :root sets --brand to teal, and three arrows carry it to a button, a link and a heading. Sass: a styles.scss file with a nested rule goes through a compile arrow and comes out as plain styles.css. CSS framework: ready-made classes such as btn, row and col-6 are dropped into the HTML, and a styled button and a two-column row appear.](https://learn.benibix.com/diagrams/dev5-css-tools.svg)

---

Source: https://learn.benibix.com/term/development/css-custom-properties
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
