CSS Variables let you store values once and reuse them everywhere. Perfect for theming and consistency.
:root {
--primary: #00bcd4;
--text: #0d1b2a;
--radius: 10px;
--spacing-md: 16px;
}
Variables on :root are global. The -- prefix is required.
button {
background: var(--primary);
border-radius: var(--radius);
padding: var(--spacing-md);
}
/* Fallback if undefined */
color: var(--accent, #ff6b6b);
document.documentElement.style
.setProperty("--primary", "#ff6b6b");