<var>
Widely availableSince 201797% of users
Lets you insert the value of a custom property (CSS Variable) into your stylesheet, making it easier to reuse colors, spacing and other values across your design.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyClassicIt has worked everywhere since April 2017.
The old way and the modern waySee the snippet: Theme variables without a preprocessor →
Old way 7 lines
// Sass/LESS: compile-time only
$primary: #7c3aed;
$spacing: 16px;
.btn {
background: $primary;
padding: $spacing;
}Modern 7 lines
:root {
--primary: #7c3aed;
--spacing: 16px;
}
.btn {
background: var(--primary);
}See how modern your own CSS is.Check your CSS →
Quick example
:root {
--primary: #3366ff;
}
.button {
/* Uses the variable defined above */
background-color: var(--primary);
/* Optional: providing a fallback color in case the variable is missing */
color: var(--text-color, white);
}<var> browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2017.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
49+
31+
9.1+
15+Mobile
49+Android
31+Android
9.3+iOS