CSS Variables let you store reusable values like colors, sizes, and more — making your styles easy to manage and update.
Resize your browser to see the boxes adjust their size and font dynamically!
:root { --primary-color: #3498db; --secondary-color: #2ecc71; --font-size: 18px; --box-size: 150px; } .box { background-color: var(--secondary-color); font-size: var(--font-size); width: var(--box-size); height: var(--box-size); }
@media (max-width: 600px) { :root { --box-size: 100px; --font-size: 14px; } }
1. How do you declare a CSS variable?
2. Where should global variables be defined?
3. How do you use a variable in CSS?