CSS & LayoutBaseline · Widely

CSS Custom Properties & Cascade

Mental Model

CSS Custom Properties (--token) are live, inheriting cascade values resolved at computed-value time rather than compile time. Because var() bypasses parse-time type checks, a mismatched substitution triggers Invalid At Computed Value Time (IACVT), resetting the property to its initial value instead of an earlier CSS line.

Interactive Simulator

var() Substitution & IACVT Fallback

Trace how custom properties pass parse time, inherit, and trigger IACVT.

Parse Time
Inherit Tree
var() Sub
Step 1 / 3: 1. Parse-Time Token Capture

Declarations with var() always pass CSS syntax parsing, discarding earlier static fallbacks.

background: blue;
background: var(--missing, 12px); /* Passes parse! */
Internal State / Memory
parseValid
true
fallbackDiscarded
blue

Under the Hood

Sass variables are baked into concrete numbers before the browser ever sees them; CSS custom properties are live pointers evaluated inside Specificity & Inheritance.

  1. Parse-Time Optimism: Any rule containing var() is assumed valid during parsing, so earlier fallback lines are thrown away.
  2. Inheritance: --tokens inherit down the DOM unless overridden by a closer ancestor or @property with inherits: false.
  3. IACVT Reset: If var(--bg) resolves to 12px inside background, it becomes Invalid At Computed Value Time, falling back to initial (transparent), not the line above.
CSS
.alert {
  /* Use var() inline fallback, not a separate line above */
  background: var(--alert-bg, #fef2f2);
  color: var(--alert-fg, #991b1b);
}

To add parse-time type safety and animation interpolation, upgrade key tokens with CSS Houdini @property.

Problem Genealogy

  • 2009–2015: Sass/Less variables solved static theming but could not respond to media queries, @container, or runtime dark-mode toggles without duplicating CSS.
  • 2016+: CSS Custom Properties shipped across browsers, turning design tokens into runtime cascade primitives.

Production Pitfalls

Production Pitfall
  • Mutating :root variables on scroll or mousemove: Updating --x on document.documentElement invalidates inherited styles across thousands of elements per frame.
  • Space-toggle tricks: Overly clever --on: initial; --off: ; hacks hurt readability and break minifiers; prefer explicit classes or container style queries.
When Not to Use
  • When not to use custom properties: Avoid putting high-frequency per-frame animation coordinates on :root; animate transform or scope the variable to the single animated element.

Connections & Logical Next Steps

CSS & LayoutCSS Custom Properties & Cascade

Seen in Architecture Autopsies

Mechanical Comparisons