Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
CSS Variables, Transitions & Keyframe Animations 15 mins read Free Lesson

CSS Custom Properties (CSS Variables) & Theming

Declare root variables with --var-name, use var(), and implement effortless Dark Mode theming.

CSS Custom Properties

:root {
    --primary: #6366f1;
    --bg-surface: #ffffff;
    --text-main: #0f172a;
}

/* Dark Theme Override */
[data-theme="dark"] {
    --bg-surface: #0f172a;
    --text-main: #f8fafc;
}

body {
    background-color: var(--bg-surface);
    color: var(--text-main);
}

.btn-primary {
    background-color: var(--primary);
}