You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-conditional-5] Feature detection for descriptors #2463
Currently, @supports and CSS.supports only support property: value pairs. The only way for web developers to detect support for a certain descriptor in an at-rule is to use JavaScript. For example:
Tagged as "unknown/future spec" for now, because I'm not sure if we should extend @supports (which is in css-conditional), or develop a new mechanism for it.
Yeah, it's Conditional - this is precisely why we took care to include arbitrary functional terms in the @supports grammar which resolve to unknown, so we can add more types of support-testing in the future.
(Need to also be able to test for types, like if "1foo" is a <length>, etc.)
(Need to also be able to test for types, like if "1foo" is a , etc.)
Maybe. We have a clear syntax extension path if we want to, but why do we need to test if 1foo is supported independently of testing if bar: 1foo is supported?
Maybe. We have a clear syntax extension path if we want to, but why do we need to test if 1foo is supported independently of testing if bar: 1foo is supported?
Yeah, one could do that, but given that UAs will have explicit parsers for each value type for Typed OM purposes, we'll be able to expose that directly, if it makes one's intent clearer.
Sure, but when you want to use a value, you're going to use it somewhere. And it is possible that the UA supports that value without supporting it where you planned to use it.
For instance, a newer version of a property may accept % and length while the old one only took %. The browser you're in does not yet support the length version yet, but does support the new fancy length unit you want to use in places where it does support length.
In that sense, while @supports unit(1ch) would something that is technically true, it seems a bit of a footgun: @supports unit(1ch) { prop-that-used-to-take-percent-only: 1ch; }
The unit(…) function could only be exposed from within CSS.supports(…) but not from @supports, that would solve the footgun issue while allowing developers to test for unit support from JavaScript, also the unit(…) function is off‑topic and should be discussed in a separate issue.
Especially in [css-properties-values-api] currently implemented by Chrome, syntax: '<image>' is not yet supported, which makes it difficult to detect it. cc @andruud
@yisibl My point exactly. I only want a @font-face block if the browser supports size-adjustandascent-override. Supporting size-adjustbut notascent-override makes things worse than not supporting size-adjust at all
changed the title [-][css-conditional-4] Feature detection for descriptors[/-][+][css-conditional-5] Feature detection for descriptors[/+]on Nov 6, 2024
It's definitely more verbose as afaik you'd need to provide a complete valid @property rule instead of just the descriptor on its own. Then again, some descriptors' requirements depend on what other descriptors are specified.
Activity
svgeesus commentedon Mar 22, 2018
I agree that being able to detect descriptor support is valuable. I would have thought it belongs in CSS Conditional.
tabatkins commentedon Mar 22, 2018
Yeah, it's Conditional - this is precisely why we took care to include arbitrary functional terms in the @supports grammar which resolve to unknown, so we can add more types of support-testing in the future.
(Need to also be able to test for types, like if "1foo" is a
<length>, etc.)tabatkins commentedon Mar 22, 2018
Something like
@supports descriptor(@media, font-display: block) { ... }.frivoal commentedon Mar 23, 2018
@tabatkins Did you mean to write:
frivoal commentedon Mar 23, 2018
Maybe. We have a clear syntax extension path if we want to, but why do we need to test if
1foois supported independently of testing ifbar: 1foois supported?[-]Feature detection for descriptors[/-][+][css-conditional-4] Feature detection for descriptors[/+]tabatkins commentedon Mar 23, 2018
Yes, I did mean that.
Yeah, one could do that, but given that UAs will have explicit parsers for each value type for Typed OM purposes, we'll be able to expose that directly, if it makes one's intent clearer.
frivoal commentedon Mar 23, 2018
Sure, but when you want to use a value, you're going to use it somewhere. And it is possible that the UA supports that value without supporting it where you planned to use it.
For instance, a newer version of a property may accept % and length while the old one only took %. The browser you're in does not yet support the length version yet, but does support the new fancy length unit you want to use in places where it does support length.
In that sense, while
@supports unit(1ch)would something that is technically true, it seems a bit of a footgun:@supports unit(1ch) { prop-that-used-to-take-percent-only: 1ch; }ExE-Boss commentedon Oct 17, 2018
The
unit(…)function could only be exposed from withinCSS.supports(…)but not from@supports, that would solve the footgun issue while allowing developers to test for unit support from JavaScript, also theunit(…)function is off‑topic and should be discussed in a separate issue.mrego commentedon Apr 24, 2020
It'd be nice to have this for
@propertyso we could feature detect the support from CSS directly with something like:yisibl commentedon Apr 24, 2020
Yeah,
@propertyurgently needs this feature, Chrome is ready to ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/3ygpsew53a0yisibl commentedon Apr 24, 2020
Especially in [css-properties-values-api] currently implemented by Chrome,
syntax: '<image>'is not yet supported, which makes it difficult to detect it. cc @andruud36 remaining items
Bug 1928335 [wpt PR 48907] - Implement at-rule for use with @supports.…
ExE-Boss commentedon Nov 5, 2024
@yisibl
Safari 16 is still quite big, as it’s the last version to support iPhone 8 (last iPhone model before Face ID; excluding iPhone SE 3) and iPhone X.
stoyan commentedon Nov 5, 2024
@yisibl My point exactly. I only want a
@font-faceblock if the browser supportssize-adjustandascent-override. Supportingsize-adjustbut notascent-overridemakes things worse than not supportingsize-adjustat all[-][css-conditional-4] Feature detection for descriptors[/-][+][css-conditional-5] Feature detection for descriptors[/+]Bug 1928335 [wpt PR 48907] - Implement at-rule for use with @supports.…
yisibl commentedon Sep 10, 2025
Microsoft's new proposal:
See https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/AtRuleFeatureDetection/explainer.md#detect-whether-a-given-declaration-is-supported-within-an-at-rule-block
AtkinsSJ commentedon Sep 10, 2025
See also the suggestion in #12622 which could do the same detection with something like this:
It's definitely more verbose as afaik you'd need to provide a complete valid
@propertyrule instead of just the descriptor on its own. Then again, some descriptors' requirements depend on what other descriptors are specified.Bug 1928335 [wpt PR 48907] - Implement at-rule for use with @supports.…
[css-conditional-5] Spec at-rule() per CSSWG resolutions. w3c#2463, w…
[css-conditional-5] Spec at-rule() per CSSWG resolutions. #2463, #6966,
fix: evaluate supported at-rules in feature queries
fix: evaluate supported at-rules in feature queries