Lesson 24 of 50
cssCSS Custom Properties (Variables)
9 mins
Course progress48%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 24 of 50
css9 mins
Keep these ideas in mind as you work through the lesson.
Custom properties are reusable values that cascade just like any other property.
:root { --primary:#0066cc; --spacing:1rem; }
.button { background:var(--primary); margin:var(--spacing); }
You can update them at runtime with JavaScript (element.style.setProperty('--primary','#ff6600')).
:root { --bg:#fff; --text:#111; }
[data-theme="dark"] { --bg:#111; --text:#eee; }
body { background:var(--bg); color:var(--text); }