<if>
Limited availability73% of usersExperimental
An experimental function that allows you to apply different values based on a condition (like a media query or a variable state) directly within a property value.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyComingNot in Firefox or Safari yet, so not every major browser supports it.
The old way and the modern waySee the snippet: Inline conditional styles without JavaScript →
Old way 13 lines
/* Multiple class variants */
.btn {
background: gray;
}
.btn.primary {
background: blue;
}
.btn.danger {
background: red;
}
/* Plus JS to manage state:
el.classList.toggle('primary', isPrimary); */
/* Duplicated rules per variant */Modern 6 lines
.btn {
background: if(
style(--variant: primary): blue;
else: gray
);
}See how modern your own CSS is.Check your CSS →
Quick example
button {
/* Experimental: change padding based on a wide screen variable */
padding: if(var(--is-wide): 1rem 2rem; else: 0.5rem 1rem);
}Related snippet
Inline conditional styles without JavaScriptWorkflow →<if> browser support
BaselineLimited availabilityThis feature is not Baseline because it does not work in some of the most widely-used browsers.Not ready for production without a fallback.
Usage73%of people can use this27% use a browser without it.
Browsers
137+
137+Mobile
137+Android
Interop 2027 candidate. Tracked for Interop 2027. Official focus areas publish early 2027; proposals are open through September 2026. See Interop 2027 →