CSS custom properties (variables) enable reusable design tokens and dynamic theming.
Variable pattern
:root { --brand-600: #4f46e5; }\n.button { background: var(--brand-600); }
Production checklist
- Define global tokens in
:root. - Scope component overrides carefully.
- Provide fallback values where needed.
Important interview questions and answers
- Q: Why CSS vars over preprocessor vars?
A: CSS vars are runtime-aware and can change per element/context. - Q: Can variables be animated?
A: Some can, especially with typed registration via@property. - Q: Best use case?
A: Theming and consistent spacing/typography/color systems.
Practice: Change one property in the playground and observe cascade + layout in DevTools.