Provide Safe Colour Fallbacks
Keep a declaration usable when an optional custom property is missing.
Use the second argument to var()
background: var(--demo-surface, #fef3c7);
The browser uses #fef3c7 when --demo-surface
is missing or invalid. A fallback does not replace a valid but poorly
chosen colour.
A component with optional theme values
Fallback notice
This notice does not define any --demo-* properties, so
each colour comes from a readable fallback in its declaration.
Theme checklist
- Name values by role, not by a colour such as blue or orange.
- Define the shared palette in
:root. - Override related values together on a container.
- Add fallbacks where an absent value would break the declaration.
- Test text, controls, states, borders, and focus indicators.