On this page
var()
Prev: color | Up: color | Next: `oklch()`
Rel: color, Color & Value Functions Guide
Ref: MDN Web Docs — var()
Tags: #public #web #css #functions #color #tier/core
Syntax & Overview
var(--surface, #ffffff)
Substitutes a CSS custom property value with an optional fallback.
Notes & Best Practices
- Supports inline fallback values (
var(--gap, 1rem)) and even nested fallbacks. - Inherited through the DOM cascade: Override a token on a component class without rewriting its rules.
Example
:root { --radius: 8px; }
.card { border-radius: var(--card-radius, var(--radius)); }
.card--pill { --card-radius: 999px; }
Linked from
Related notes
- tuts/css/functions/color/oklch Linked here; links to this page; shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/color Linked here; links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color_and_value_functions Linked here; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/color-mix shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/color/light-dark shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/color/linear-gradient shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/math/calc shared tags: #css, #functions, #tier, #web
- tuts/css/functions/math/clamp shared tags: #css, #functions, #tier, #web
- tuts/css/functions/math/min shared tags: #css, #functions, #tier, #web
- tuts/css/functions/math/minmax shared tags: #css, #functions, #tier, #web