Skip to content
CSS·Advanced·Coding·1 min read

What happens when var(--missing) references a custom property that was never defined, with no fallback given?

Short interview answer

The property using var() computes to its inherited or initial value, depending on whether it's an inherited property, effectively invalid at computed-value time for that declaration; providing a second argument to var() as a fallback avoids relying on that behavior and keeps the rule predictable.

Example

CSS
color: var(--brand, #e2521f);   /* fallback used if --brand is undefined */

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Custom properties and theming

Related questions