The CSS cascade resolves competing declarations using origin, importance, layer, specificity, and source order. A design token is a named custom property that carries a decision such as a spacing step or surface color into several components. Layers help define which group of normal declarations may override another before specificity becomes a fight. Put reset, foundation, component, and utility rules in a known order. Keep tokens near the scope that owns them: a global color may be shared, while a case-card density choice can belong to the card. Remember that unlayered normal author styles can outrank layered normal styles, so a stray rule outside the declared layer plan can defeat it.
Cascade Layers and Design Token Ownership
Working case
A third-party button stylesheet enters the case dashboard and changes the review action's padding. The team adds an increasingly specific selector to fight it; a later dialog gets the wrong spacing anyway. Put vendor rules in a lower-priority layer, components above them, and a documented utility layer last for deliberate one-off overrides. Expose a compact spacing token for the review toolbar instead of repeating pixel values across the dashboard and drawer. Check focus and contrast after a theme change; changing one token can affect many screens.
Implementation boundary
@layer vendor, foundation, components, utilities;
@layer foundation { :root { --space-review: 0.75rem; --surface-review: #f5f7fa; } }
@layer components { .case-toolbar { display: flex; gap: var(--space-review); background: var(--surface-review); } }
@layer utilities { .case-toolbar--compact { --space-review: 0.5rem; } }Declare the layer order before importing or writing component rules, and place third-party CSS into its intended layer. The custom property override is scoped to the compact toolbar so it does not change unrelated pages. A token name should describe the decision it controls rather than encode a current value that may later change. Do not use !important as a routine escape from poor ordering. Important declarations have their own cascade behavior, so review them separately rather than assuming the normal layer order explains every result.
Cost and boundaries
Custom property resolution and layered style matching are ordinary style work, but a large token graph can be hard to debug when values cascade through many scopes. The main benefit is controlled change: one owned decision can update several related components without copying declarations. The main risk is a token that is too broad, so a harmless-looking update changes an inaccessible surface elsewhere. Test representative states, themes, and focus indicators whenever a shared color, spacing, or motion token changes.
Failure trace
An unlayered .case-toolbar rule from a copied stylesheet takes precedence over the layered component rule. Engineers keep raising specificity inside @layer components, but the override remains in place. Inspect the computed style's cascade origin and layer, move the copied rule into its proper layer, and remove the specificity escalation. A second failure is a global spacing token used for both toolbar and error message, so a compact toolbar setting also compresses feedback. Scope the component token and retest both states.
Verification
- Vendor, component, and utility declarations resolve in the planned order.
- A compact token override affects the toolbar without changing unrelated feedback.
- Theme changes preserve contrast and focus visibility across representative states.
Practice drill
Add a vendor rule that changes toolbar padding and a local compact variant. Inspect which declaration wins before and after placing the vendor rule in its layer. Change --space-review at the card scope and verify only the intended region changes. Add an unlayered rule on purpose to see its precedence, then remove it. Review the resulting normal, focused, error, and disabled states in two themes. Record each token's owner and expected consumers.
Decision note
Use layers to state style precedence and tokens to name shared decisions; keep both scoped enough to review their effects.
Common Mistakes
- Escalating specificity to fight an unlayered rule.
- Making a component-specific token global without reviewing all consumers.
- Assuming important declarations follow the same precedence as normal ones.
Connected lessons
CSS Layout and Interface Systems; Grid, Flex, and Intrinsic Size Contracts; Container Queries for Reusable Panels; Font Loading and Motion Fallbacks; Component Boundaries and State Ownership; Web Components and Shadow Boundaries; Reflow, Zoom, and Motion Preferences.
Apply and check
Build Project: adaptive review interface and review Web Development: layout and runtime contracts quiz.
