supports property

Definition and Usage

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.

It allows 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 CSSSupportsRule.


Syntax

@supports <supports_condition> {
  /* specific rules */
}

A supports condition consists of one or several declarations combined by different logical operators. Precedence of operators can be overruled by using parenthesis.

Declaration syntax

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 transform-origin implements a syntax considering 5% 5% as valid.

A CSS declaration is always surrounded by parentheses.

The not operator

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 transform-origin doesn’t implement a syntax considering 10em 10em 10em as valid.

Like any operator, the not operator can be applying 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) )

Note: there is no need to enclose the not operator between two parenthesis when at the top level. But to combine it with other operators, like and and or, the parenthesis are required.

The and operator

From two expressions, the and operator creates a new expression consisting in the conjunction of the two original ones, that is 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 parenthesis:

(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))

The or operator

From two expressions, the or operator creates a new expression consisting in the disjunction of the two original ones, that is 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 parenthesis:

( 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  )))

Note: when using both and and or operators, the parenthesis 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.


Examples

Testing for the support of a given CSS property

1 @supports (animation-name: test) {
2     … /* specific CSS applied when animations are supported unprefixed */
3     @keyframes { /* @supports being a CSS conditional group at-rule, it can includes other relevent at-rules */
4       
5     }
6 }

Testing for the support of a given CSS property or a prefixed version

1 @supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or
2             (-ms-perspective: 10px) or (-o-perspective: 10px) ) {
3     … /* specific CSS applied when 3D transforms, eventually prefixed, are supported */
4 }

Testing for the non-support of a specific CSS property

1 @supports ( not ((text-align-last:justify) or (-moz-text-align-last:justify) ){
2     … /* specific CSS applied to simulate text-align-last:justify */
3 }

Compatibility

Desktop browsers

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 28.0 22.0 (22) Not supported 12.1 Not supported

Mobile browsers

Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported 22.0 (22) Not supported 12.1 Not supported

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.