Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 24 of 50 · css

CSS Custom Properties (Variables)

Duration: 9 mins

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')).


Example: Dark‑mode toggle using CSS variables

:root { --bg:#fff; --text:#111; }
[data-theme="dark"] { --bg:#111; --text:#eee; }
body { background:var(--bg); color:var(--text); }
Previous: Responsive Design – Media QueriesNext: CSS Functions – calc(), clamp(), min(), max()