var()

The var() function substitutes the value of a CSS custom property, with an optional fallback.

Since CSS3 Spec ↗

Syntax

var(--name, <fallback>)

Examples

:root { --gap: 1rem; }
.grid { gap: var(--gap); }
.card { padding: var(--card-pad, 1.5rem); }
Output
Uses the global --gap token for grid spacing and falls back to 1.5rem when --card-pad is undefined.

Notes

Custom properties cascade and inherit, enabling runtime theming via JS or media queries. The fallback after the comma is used only if the property is not set. Invalid substitutions make the declaration use its inherited/initial value.

Browser & runtime support

EnvironmentSince version
chrome 49
firefox 31
safari 9.1
edge 15

See also