--- title: '@supports' slug: Web/CSS/@supports translation_of: Web/CSS/@supports ---
{{ CSSRef() }}
The @supports
CSS at-rule associates a set of nested statements, in a CSS block, that is delimited by curly braces, with a condition consisting of testing of CSS declarations, that is property-value pairs, combined with arbitrary conjunctions, disjunctions, and negations of them. Such a condition is called a supports condition.
@supports
gives CSS the ability to perform a feature query.
The @supports
at-rule may be used not only at the top level of a CSS, but also inside any CSS conditional-group at-rule and can be accessed via the CSS object model interface {{domxref("CSSSupportsRule")}}.
A supports condition consists of one or several declarations combined by different logical operators. Precedence of operators can be overruled by using parentheses.
The simplest expression is a CSS declaration, that is a CSS property name followed by a value, separated by a colon. The following expression
( transform-origin: 5% 5% )
returns true if the {{ cssxref("transform-origin") }} implements a syntax considering 5% 5%
as valid.
A CSS declaration is always surrounded by parentheses.
The not
operator can precede any expression to create a new expression, resulting in the negation of the original expression. The following expression
not ( transform-origin: 10em 10em 10em )
returns true if {{ cssxref("transform-origin") }} doesn't implement a syntax considering 10em 10em 10em
as valid.
Like any operator, the not
operator can be applied to a declaration of any complexity. The following examples are all valid expressions:
not ( not ( transform-origin: 2px ) ) (display: flexbox) and ( not (display: inline-grid) )
Предупреждение: there is no need to enclose the not
operator between two parentheses when at the top level. To combine it with other operators, like and
and or
, the parentheses are required.
From two expressions, the and
operator creates a new expression consisting in the conjunction of the two original ones; the resulting expression is true only if both of the original expressions also resolve to true. In this example, the complete expression resolves to true if and only if the two expressions are simultaneously true:
(display: table-cell) and (display: list-item)
Several conjunctions can be juxtaposed without the need of more parentheses:
(display: table-cell) and (display: list-item) and (display:run-in)
is equivalent to:
(display: table-cell) and ((display: list-item) and (display:run-in))
From two expressions, the or
operator creates a new expression consisting in the disjunction of the two original ones; the resulting expression is true if one, or both, of the original expressions also resolves to true. In this example, the complete expression resolves to true if at least one of the two expressions is true:
( transform-style: preserve ) or ( -moz-transform-style: preserve )
Several disjunctions can be juxtaposed without the need of more parentheses:
( transform-style: preserve ) or ( -moz-transform-style: preserve ) or ( -o-transform-style: preserve ) or ( -webkit-transform-style: preserve )
is equivalent to:
( transform-style: preserve-3d ) or (( -moz-transform-style: preserve-3d ) or (( -o-transform-style: preserve-3d ) or ( -webkit-transform-style: preserve-3d )))
Предупреждение: when using both and
and or
operators, the parentheses must be used in order to define the order in which they apply. If not, the condition is invalid leading to the whole at-rule to be ignored.
{{csssyntax}}
@supports (animation-name: test) { … /* specific CSS applied when animations are supported unprefixed */ @keyframes { /* @supports being a CSS conditional group at-rule, it can includes other relevant at-rules */ … } }
@supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or (-ms-perspective: 10px) or (-o-perspective: 10px) ) { … /* specific CSS applied when 3D transforms, eventually prefixed, are supported */ }
@supports not ((text-align-last:justify) or (-moz-text-align-last:justify) ){ … /* specific CSS applied to simulate text-align-last:justify */ }
Спецификация | Статус | Комментарий |
---|---|---|
{{ SpecName('CSS3 Conditional', '#at-supports', '@supports') }} | {{ Spec2('CSS3 Conditional') }} | Первоначальное определение. |
{{ CompatibilityTable() }}
Особенность | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Базовая поддержка | {{CompatChrome(28.0)}} | {{ CompatVersionUnknown }} | {{ CompatGeckoDesktop("22") }} [1] | {{ CompatNo() }} | 12.1 | 9 |
Особенность | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Базовая поддержка | {{ CompatNo() }} | {{CompatUnknown}} | {{ CompatGeckoMobile("22") }} [1] | {{ CompatNo() }} | 12.1 | 9 | {{CompatChrome(28.0)}} |
[1] Gecko 17 to Gecko 21 supported this feature only if the user enables it by setting the config value layout.css.supports-rule.enabled
to true
.