The @supportsCSSat-rule lets you specify CSS declarations that depend on a browser's support for CSS features. Using this at-rule is commonly called a feature query. The rule must be placed at the top level of your code or nested inside any other conditional group at-rule.
Try it
In JavaScript, @supports can be accessed via the CSS object model interface CSSSupportsRule.
Syntax
The @supports at-rule consists of a block of statements with a supports condition. The supports condition is a set of one or more name-value pairs (e.g., <property>: <value>).
@supports(<supports-condition>){/* If the condition is true, use the CSS in this block. */}
The conditions can be combined by conjunctions (and), disjunctions (or), and/or negations (not).
@supports(<supports-condition>)and(<supports-condition>){/* If both conditions are true, use the CSS in this block. */}
The precedence of operators can be defined with parentheses. Supports conditions can use either a <property>: <value> declaration syntax or a <function()> syntax. The following sections describe the use of each type of supports condition.
Declaration syntax
The declaration syntax checks if a browser supports the specified <property>: <value> declaration. The declaration must be surrounded by parentheses. The following example returns true and applies the CSS style if the browser supports the expression transform-origin: 5% 5%:
@supports(transform-origin: 5% 5%){}
Function syntax
The function syntax checks if a browser supports values or expressions within the function. The functions supported in the function syntax are described in the following sections.
selector()Experimental
This function evaluates if a browser supports the specified selector syntax. The following example returns true and applies the CSS style if the browser supports the child combinator:
@supportsselector(h2 > p){}
font-tech()
This function checks if a browser supports the specified font technology for layout and rendering. The following example returns true and applies the CSS style if the browser supports the COLRv1 font technology:
@supportsfont-tech(color-COLRv1){}
The table below describes the available font technologies that can be queried using this function:
Font variations in TrueType and OpenType fonts to control the font axis, weight, glyphs, etc.
palettes
Font palettes by means of font-palette to select one of many color palettes in the font
font-format()
This function checks if a browser supports the specified font format for layout and rendering. The following example returns true and applies the CSS style if the browser supports the opentype font format:
@supportsfont-format(opentype){}
The following table describes the available formats that can be queried with this function:
Format
Description
File extensions
collection
OpenType Collection
.otc, .ttc
embedded-opentype
Embedded OpenType
.eot
opentype
OpenType
.ttf, .otf
svg
SVG Font (deprecated)
.svg, .svgz
truetype
TrueType
.ttf
woff
WOFF 1.0 (Web Open Font Format)
.woff
woff2
WOFF 2.0 (Web Open Font Format)
.woff2
The not operator
The not operator precedes an expression resulting in the negation of the expression. The following returns true if the browser's transform-origin property considers 10em 10em 10emto be invalid:
@supportsnot(transform-origin: 10em 10em 10em){}
As with any operator, the not operator can be applied to a declaration of any complexity. The following examples are both valid:
Note: There is no need to enclose the not operator between two parentheses at the top level. To combine it with other operators, like and and or, the parentheses are required.
The and operator
The and operator creates a new expression from the conjunction of two shorter expressions. It returns true only if both of the shorter expressions are also true. The following example returns true if and only if the two shorter expressions are simultaneously true:
The or operator creates a new expression from the disjunction of two shorter expressions. It returns true if one or both of the shorter expressions is also true. The following example returns true if at least one of the two shorter expressions is true:
Note: When using both and and or operators, the parentheses must be used to define the order in which they apply. Otherwise, the condition is invalid and the whole rule is ignored.
@supports(animation-name: test){/* CSS applied when animations are supported without a prefix */@keyframes{/* Other at-rules can be nested inside */}}
Testing for the support of a given CSS property or a prefixed version
@supports(text-stroke: 10px)or(-webkit-text-stroke: 10px){/* CSS applied when text-stroke, prefixed or not, is supported */}
Testing for the non-support of a specific CSS property
@supportsnot((text-align-last: justify)or(-moz-text-align-last: justify)){/* CSS to provide fallback alternative for text-align-last: justify */}
Testing for the support of a selector
CSS conditional rules provide the ability to test for the support of a selector such as :has().
/* This rule won't be applied in browsers that don't support :has() */ul:has(> li li){/* CSS is applied when the :has(…) pseudo-class is supported */}@supportsnotselector(:has(a, b)){/* Fallback for when :has() is unsupported */ul > li,
ol > li{/* The above expanded for browsers that don't support :has(…) */}}/* Note: So far, there's no browser that supports the `of` argument of :nth-child(…) */@supportsselector(:nth-child(1n of a, b)){/* This rule needs to be inside the @supports block, otherwise
it will be partially applied in browsers which don't support
the `of` argument of :nth-child(…) */:is(:nth-child(1n of ul, ol) a, details > summary){/* CSS applied when the :is(…) selector and
the `of` argument of :nth-child(…) are both supported */}}
Testing for the support of a font technology
The following example applies the CSS style if the browser supports the COLRv1 font technology:
It's also possible to test for the support of a font technology by using the tech function inside the @font-face at-rule. If a browser doesn't support the font technology, a fallback font (Bungee-fallback.otf) can be used instead.