var()
The CSS function that reads a custom property, with an optional fallback: var(--brand, #2563eb).
In more detail
If the named property is not defined where the element sits, the browser uses the fallback instead. Components should always give one, so they still look sensible when a host application forgets to define a token. Tailwind version 4 utilities use var() to point at theme variables.
Example
In the browser: If the property is not set the fallback is used. If the property is set but its value is invalid for where it is used, the declaration falls back to the property's inherited or initial value instead, not to the var() fallback.Related terms
- CSS custom property — A value you name yourself in CSS, such as --color-primary: #2563eb, and use elsewhere with var(--color-primary).
- theming — Giving the same components different looks, such as light, dark or a different brand, by swapping the token values they use.
- CSS custom property — A property you define yourself with a double-hyphen name, such as --brand: #0066cc, and read elsewhere with var(--brand).
- fallback — A second choice used when the first is unavailable, such as a simpler layout for older browsers or a default value when a variable is missing.
Taught in
- CSS Custom Properties & Dynamic Theming Architecture — Design Systems & Component Engineering
- Tailwind CSS v4 Engine: CSS Variables & Theme Extensions — Design Systems & Component Engineering
- CSS Custom Properties: Scoping, Fallbacks And Theming — Frontend Architecture & Web Platform