Advertisement

CSS Variables & Media Queries

Previous Lesson 228 of 228 Take CSS Quiz →
Advertisement
Lesson Overview: Build dark themes and responsive breakpoints cleanly using custom properties (--var) and @media.

Dynamic Theme Tokens

Declare variables on :root (--brand: #04AA6D;) and reference them via var(--brand). Override variables inside a .dark class to switch whole themes in milliseconds.

CSS Custom Properties + Responsive Rule (Editable — type & Run)

Advertisement

Test Yourself With Exercises

Reference a CSS variable named --accent:

.btn { background: (--accent); }
Pro Tip: CSS variables cascade just like normal properties and can be read/changed from JavaScript.
Advertisement