CSS.supports()
The CSS.supports()
static methods returns a Boolean
value indicating if the browser supports a given CSS feature, or not.
Syntax
JavaScript
Copy Code
boolValue = CSS.supports(propertyName, value); boolValue = CSS.supports(supportCondition);
Parameters
There are two distinct sets of parameters. The first one allows to test the support of a pair property-value:
- propertyName
- A
DOMString
containing the name of the CSS property to check. - value
- A
DOMString
containing the value of the CSS property to check.
The second syntax takes one parameter matching the condition of @supports
:
- supportCondition
- A
DOMString
containing the condition to check.
Examples
JavaScript
Copy Code
result = CSS.supports("text-decoration-style", "blink"); result = CSS.supports("display", "flex"); result = CSS.supports('--foo', 'red'); result = CSS.supports('(--foo: red)'); result = CSS.supports("<code class="language-css">( transform-origin: 5% 5% )"); result = <code class="language-css">CSS.supports("( transform-style: preserve ) or ( -moz-transform-style: preserve ) or " + "( -o-transform-style: preserve ) or ( -webkit-transform-style: preserve )" );</code></code>
Specification
Specification | Status | Comment |
---|---|---|
CSS Conditional Rules Module Level 3 The definition of 'CSS.supports()' in that specification. |
Candidate Recommendation | Initial definition. |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 28.0 | 12 | 22 (22) [1] | No support | 12.1 | 9 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | No support | 22.0 (22) [1] | No support | 12.1 | 9 |
[1] Gecko 20 and 21 supported this feature only if the user enables it by setting the config value layout.css.supports-rule.enabled
to true
.
See also
- The
@supports
at-rule that allows for the same functionality but in a declarative way. - The
CSSSupportsRule
CSSOM class allowing to manipulate@supports
at-rules.
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/css/supports