@supports: progressive enhancement for new CSS in a theme
A theme that uses new CSS features faces the same question again and again: what do visitors with an older browser see? @supports answers it explicitly. The basic layout works everywhere, and the enhanced version applies only where the browser understands the feature, tested by a declaration, a selector, or a font technology. Written that way, new features can be used years before every visitor’s browser has them.
Problem: A theme uses :has() to style cards that contain an image, CSS nesting, and anchor positioning for tooltips. On an older iPad, the cards collapse, and the tooltips appear at the top of the page.
Solution: Write a complete baseline that works without the new features, put each enhancement into @supports with the exact feature it needs (selector(:has(*)), a property-value pair, or not for a fallback), avoid nesting in the baseline, and test the baseline by disabling the feature in DevTools or in an older browser.
Feature queries by declaration
/* baseline */
.ha-card { display: block; }
@supports (display: grid) and (gap: 1rem) {
.ha-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
}
@supports (anchor-name: --a) {
.ha-tooltip { position-anchor: --ha-tip; position-area: top; }
}
@supports not (color: oklch(0 0 0)) {
:root { --ha-accent: #2563eb; } /* fallback for the oklch() accent */
}
The test is a property with a value in parentheses; it is true when the browser can parse that declaration. and, or and not combine tests. The not form is the clean way to add fallbacks for the few browsers without a feature, instead of overriding everything for modern ones.
Selector support
.ha-card { padding: 1rem; }
@supports selector(:has(img)) {
.ha-card:has(> img) { padding: 0; }
.ha-card:has(> img) .ha-card__body { padding: 1rem; }
}
selector() tests whether a selector is understood. Without the wrapper, browsers that do not know :has() would drop the rules anyway, because an invalid selector invalidates its rule. The wrapper matters when the enhanced rule is combined with resets of the baseline, as above: both changes must apply together, or neither.
Nesting and feature queries
A browser without CSS nesting cannot read nested rules even inside a supported @supports block, and it may skip following declarations while recovering from the parse error. Keep the baseline unnested and use nesting only inside enhancements that also require newer features: native CSS nesting.
In JavaScript
if ( CSS.supports( 'anchor-name', '--a' ) ) {
// CSS handles the tooltip position
} else {
import( './tooltip-position.js' );
}
CSS.supports() runs the same tests from JavaScript, to load a fallback script only where it is needed: CSS anchor positioning.
Limits
A positive @supports result means the browser parses the declaration, not that the feature is fully or correctly implemented; partial implementations (an older syntax, a missing sub-feature) still pass. For features with known differences, test the specific value that differs. And @supports does not test media features or at-rules like @container directly; @supports at-rule(@container) is being specified but not yet usable everywhere.
NOTE: @supports itself works in every browser that WordPress themes reasonably target (since 2013–2015), and selector() since 2020–2022. The pattern scales: a theme can adopt one new feature at a time, each behind its own query, as the support data allows. The if() function moves similar conditions into single values: CSS if().