Custom Properties

What this is. A custom property is a variable you define in CSS and reuse anywhere.

`

:root {

--brand: #B9834F;

}

.button { background: var(--brand); }

`

Declared on :root, it is available to the entire document, because every element inherits from the root.

Why this matters more than saving typing. Once your colors and spacing live in named variables, changing your brand color is one edit instead of forty. More importantly, the names document your intent: --brand and --ink-muted say what a value is for, while #B9834F says only what it is.

✦ Name by role, not by appearance

Call it --brand rather than --gold. If you later change the brand to green, a variable called --gold containing green is worse than no variable at all. The same logic applies to --space-md rather than --space-16.

Theming falls out for free. Because custom properties cascade, redefining them under a different selector re-themes everything that uses them, with no other change.

LIVE PREVIEW
loading editor…

Both cards use identical rules. Only the variable values differ, and the second card redefines them for itself and its children.

Your turn → Change --brand on :root to a completely different color. Every use of it updates at once, including the border, the heading, and the light card, but not the dark card, which overrides it.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Transitions, Transforms, and Respecting Motion →
← Back