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] testing support of properties and values with partial implementations #3559
There are a few places where @supports is unable to help authors as the property and value they want to test for is supported by the user agent, but not in the context they want to use it.
The obvious one (and where it keeps coming up at the moment) is testing support of any of the gap properties column-gap, row-gap or gap. I can test for support of column-gap and every browser will tell me it has support, however if I then try to use it in flexbox, I will only get a gap in Firefox, as that is the only user agent to have an implementation right now.
This means authors can't create a nice fallback with margins, then removing the margin on testing for support. It is likely that other box alignment properties - perhaps as browsers start to implement them for block layout, will have the same issue.
Other places this might be an issue are for fragmentation, I might want to test if fragmentation properties are available in a certain context.
It feels as if we need a way to ask for support of, for example, column: gap in display: flex. I don't know if that is even feasible in implementations, but it seems that this is likely to continue to be an issue as specs become more modular.
I found an older issue which also refers to partial implementations not being testable: #1167
Reacted by Ilya Streltsyn, Uli Troyo, Jonathan Schofield, Pavel Klimashkin, Giancarlo Calderón Cárdenas, Matsuko, Lara Karki, Pascal Duez, Tracy Rotton, Sora2455 and 43 more
Reacted by jarotg
Reacted by Anoesj Sadraee, Zach Leatherman and Oswaldo Freitas
This also comes up all the time when dealing with properties from SVG that are crossing over into CSS box layout & vice versa. For things like filter we have had browsers that support one syntax for SVG elements only, and a different syntax for everything except SVG elements, and both syntaxes would pass an @supports test.
(Aside: I really wish the spec for gap had strongly encouraged browsers not to support the generic property name until they implemented support for the generic feature. I was rather disappointed when browsers rushed to ship the easy parser implementation of the synonym before addressing their layout code, for this reason. But the broader issue still remains.)
Reacted by Florian Rivoal, Uli Troyo and Tim van der Horst
Perhaps the request should be that, in the absence of finer granularity queries, @supports should return false unless the implementation support exists in all usage contexts.
"Perhaps the request should be that, in the absence of finer granularity queries, @supports should return false unless the implementation support exists in all usage contexts."
That might be a bit more useful, however then there is a property and value that the author knows is supported, but seems to be returning false. At that point we are asking them to understand all possible contexts in which that property vould be used.
The fragmentation properties are probably better to look at here than gaps, which are likely to be implemented - say if we did a specific masonry layout or something.
At the moment a property like break-before: avoid is specified for multicol, paged media, and regions. Assuming a wonderful world in which the property was supported in multicol and paged media, regions is a long way off, and probably won't happen in the current form. Which would mean that testing for break-* properties would be useless for the foreseeable future, as we don't have Regions so it can't be implemented in them. Most authors aren't even going to know about Regions and therefore why the property is returning false.
There's no good solution to this that doesn't break the fundamental value proposition of @supports, which is that, since it's based purely on "does it parse", it requires no special table of return results in the browser, which history has shown us is destined to become some combination of stale and lies. I'm strongly against anything that tries to get "special-case" answers like this that aren't backed by a simple "try to parse it" mechanism.
(I definitely feel the pain, but it's not solveable here without making things overall worse.)
Though @supports(position:sticky) currently parses for all major vendors, Blink, which has the largest market share, still doesn't *fully support the value.
It seems that for some reason Chrome reverted their changes for fixing position:sticky behavior on thead element.
@tabatkins I understand your sentiment about making things worse, but currently the often most efficient ways to deal with false @support scenarios are selector hacks, even if...
Using hacks that assume support for X is equivalent to support for Y is a bad idea if those hacks are targeting current browsers. Such hacks are safe only if the features are implemented in all current browsers and the equivalence holds in the old versions where they're not implemented.
And the resolution in #3051 seems to express an opposite stance, getting rid of the ability to use some of these selector hacks.
Yup, selector hacks (or other browser-selection mechanisms) aren't great, but again, we already know that manually-maintained lists of support eventually rot, every single time it's ever been tried.
So it's a choice of somewhat encouraging bad individual-author behavior, or speccing bad UA behavior. I think the former does less damage overall.
Given, gap properties already exist for grid i.e. grid-gap, grid-column-gap, grid-row-gap, aliases for gap properties could also be added for Flexbox. This would enable detection for gap support specifically in Flexbox using the existing Feature Query syntax. For example:
@supports (flex-gap: 10px) {
div {
display: flex;
gap: 10px;
}
}
@supports not (flex-gap: 10px) {
div {
display: flex;
margin: 10px;
}
}
I'm not sure however, how appropriate this approach would be regarding other properties.
It certainly seams that as there is greater cross-pollination between specifications, this kind of situation is likely to become more prevalent and a sustainable solution would be nice.
Reacted by Jonathan Schofield, Giancarlo Calderón Cárdenas, Benny Powers, Amber, Chung Wu, Benoît Rouleau, Anoesj Sadraee, Adam Argyle, jimmyfrasche, Sid Vishnoi and 13 more
@simlawr That solution would somewhat cleanly solve the current issue regarding the -gap properties, as authors can easily understand it.
Though I believe it doesn't scale because it means that for every new property that is shared between different contexts, there needs to be an alias introduced only for the purpose of feature detection. That burdens authors, as they have to remember the aliases when doing feature detection, implementors, as they have to implement the aliases only applying in certain contexts, spec. authors because they will have to remember to add those aliases when the property is used in different contexts, and documentation writers because they will also have to cover those aliases.
Unfortunately, I don't have a better solution for this. There is probably no automated way of doing this kind of feature detection.
I really like Rachel's original suggestion although I would change it to "with" rather than "in" because you are more looking for a generic relationship between the 2 rather than a parent/child relationship.
@supports(gap:1px) with (display: flex){/* css code */}
It doesn't sound that impossible for the computer to recognise.
The browser would need to check if both of the following conditions are true:
It understands both properties.
At least one of the properties has any sort of effect on the other.
If not then it returns false.
I am probably grossly simplifying the problem though. 😅
Reacted by Cory Birdsong, Mathew, Jacob Bearce, Tomasz Jakut, jarotg, Sebastian Zartner, Ricky, Colin Fahrion, David Wheatley, yinon and 4 more
Reacted by David Wheatley, Renato de Leão and Gábor Juhász
In the case of flex gap specifically, is there any workaround for web developers to detect support for it? It's only recently shipped in Chrome and even more recently landed in Safari Technology Preview, and without feature detection people will need to wait for another 3 years or so to be able to simply assume it will work.
// Set up a cache to prevent a DOM element from getting created for every use of the functionletisSupported;functioncheckFlexGapSupport(){// Use the cached value if it has been definedif(isSupported!==undefined){returnisSupported}// Create a flex container with row-gap setconstflex=document.createElement('div')flex.style.display='flex'flex.style.flexDirection='column'flex.style.rowGap='1px'flex.style.position='absolute'// Create two, elements inside itflex.appendChild(document.createElement('div'))flex.appendChild(document.createElement('div'))// Append to the DOM (needed to obtain scrollHeight)document.body.appendChild(flex)// Flex container should be 1px high due to the row-gapisSupported=flex.scrollHeight===1// Remove element from the DOM after you are done with itflex.parentNode.removeChild(flex)returnisSupported}
Reacted by Philip Jägenstedt, Andreas Sander, Colin Fahrion, Reinhard Hutter, Max, Tim van der Horst, Rahul Gandhi, Mathias Bynens, FrLearninGJS and Diana
Even if some browsers already support gap in flexbox without this feature detection, it would still be great to add a keyword for it.
As @romainmenkepointed out earlier, making existing versions of browser apply the fallback implementation with margins instead of using gap would often be acceptable, while still using gap for newest browsers and supporting a fallback for browsers without support for gap.
so I did not follow all the threads surrounding this or have read all minutes... I would be a user of this feature.
FWIW a syntax like @supports feature(gap-on-display-flex) seem very counter intuitive and artificial in nature.
It requires learning a (albeit limited) vocabulary to describe a problem, requires maintenance (in code and documentation) and specific documentation (lists) that would be hard to "guess" where to find. And whomever writes a blog post would also need to mention these magic keywords and all existing documentation on either the main or supplemental feature would be outdated.
Some generic feature test on the other hand like @supports (gap: 1px) with (display: flex) seems more intuitive to me as it describes spot on the query of a problem that needs solving: does this work in the context of that?
Thank you folks for your great work!
Have a nice time.
Some generic feature test on the other hand like @supports (gap: 1px) with (display: flex) seems more intuitive to me as it describes spot on the query of a problem that needs solving: does this work in the context of that?
I think the basic reason not to do this is that there are probably a few thousand different options for the things on either side of the with in your proposal (different CSS properties, plus different generations of values added to those properties over time), which means there are a few million possible with combinations. There's no ready source of data for the answer to those few millions of questions, so we (both the working group and implementors) would need to sit down and decide what the correct answer to each one is, ensure engines implement them correctly, and test them.
If you combine that with the reality that there's a single digit number of these questions that we know are much more interesting than all the others, it seems much more solvable to deal with the single digit number of questions than with a few million questions.
@dbaron Thanks for your reply! I believe this makes sense :-)
My thinking was: the CSS engine should-would eventually know anyway if any property is "valid" within a specific context as it has to render it at some point and decide if it knows what it's about. And we can already have a gazillion warnings abourt invalid / unsupported properties in the console -- like vendor prefixed stuff.
But maybe this "path" is too expensive to follow in the initial parser level.
Is there a reason the previous suggestions list the display type last? It seems more intuitive to me to have keywords that list the display type first and then follow it with the requested feature.
feature(flex-gap)
Using feature() is not my favorite solution.
Since the current resolution is to implement keywords only on rare occasions (1 a year, per the log) and to make it easy to educate everyone to use with minimal confusion, I think it would be better to use a keyword that screams "this is a very special use case" rather than a generic term like feature(). I think using feature() sets a reasonable expectation that you can check for any set of CSS features, and it will cause confusion when it doesn't work that way.
Even something like case() or keyword() or just key() seems better to me (though I don't love any of those).
I'm concerned that one-off keywords will greatly increase the burden on the author's memory.
I have a @feature proposal, This is flexible enough to essentially do what JS currently does to create empty elements for detection. But I am not sure it's feasible.
My thinking was: the CSS engine should-would eventually know anyway if any property is "valid" within a specific context as it has to render it at some point and decide if it knows what it's about.
Not really. Whether a property has an effect in a specific context depends on whether we wrote code in that module to handle it. There's judgement of all properties, it's just that at the point in the layout algorithm where you need to check a property, you check it. For example in flex layout, support for gaps looks like including the value of the gap property in various equations scattered throughout the flex layout code. As dbaron notes, this is not something that the engine has a database of and can query.
Activity
AmeliaBR commentedon Jan 26, 2019
This also comes up all the time when dealing with properties from SVG that are crossing over into CSS box layout & vice versa. For things like
filterwe have had browsers that support one syntax for SVG elements only, and a different syntax for everything except SVG elements, and both syntaxes would pass an@supportstest.(Aside: I really wish the spec for
gaphad strongly encouraged browsers not to support the generic property name until they implemented support for the generic feature. I was rather disappointed when browsers rushed to ship the easy parser implementation of the synonym before addressing their layout code, for this reason. But the broader issue still remains.)nigelmegitt commentedon Jan 28, 2019
Perhaps the request should be that, in the absence of finer granularity queries,
@supportsshould returnfalseunless the implementation support exists in all usage contexts.rachelandrew commentedon Jan 28, 2019
That might be a bit more useful, however then there is a property and value that the author knows is supported, but seems to be returning false. At that point we are asking them to understand all possible contexts in which that property vould be used.
The fragmentation properties are probably better to look at here than gaps, which are likely to be implemented - say if we did a specific masonry layout or something.
At the moment a property like
break-before: avoidis specified for multicol, paged media, and regions. Assuming a wonderful world in which the property was supported in multicol and paged media, regions is a long way off, and probably won't happen in the current form. Which would mean that testing for break-* properties would be useless for the foreseeable future, as we don't have Regions so it can't be implemented in them. Most authors aren't even going to know about Regions and therefore why the property is returning false.tabatkins commentedon Jan 29, 2019
There's no good solution to this that doesn't break the fundamental value proposition of
@supports, which is that, since it's based purely on "does it parse", it requires no special table of return results in the browser, which history has shown us is destined to become some combination of stale and lies. I'm strongly against anything that tries to get "special-case" answers like this that aren't backed by a simple "try to parse it" mechanism.(I definitely feel the pain, but it's not solveable here without making things overall worse.)
jonjohnjohnson commentedon Jan 30, 2019
Related...
Though
@supports(position:sticky)currently parses for all major vendors, Blink, which has the largest market share, still doesn't *fully support the value.@SelenIT #2155 (comment)
@tabatkins I understand your sentiment about making things worse, but currently the often most efficient ways to deal with false
@supportscenarios are selector hacks, even if...@dbaron #3051 (comment)
And the resolution in #3051 seems to express an opposite stance, getting rid of the ability to use some of these selector hacks.
tabatkins commentedon Feb 2, 2019
Yup, selector hacks (or other browser-selection mechanisms) aren't great, but again, we already know that manually-maintained lists of support eventually rot, every single time it's ever been tried.
So it's a choice of somewhat encouraging bad individual-author behavior, or speccing bad UA behavior. I think the former does less damage overall.
simlawr commentedon Feb 15, 2019
Given, gap properties already exist for grid i.e.
grid-gap,grid-column-gap,grid-row-gap, aliases for gap properties could also be added for Flexbox. This would enable detection for gap support specifically in Flexbox using the existing Feature Query syntax. For example:I'm not sure however, how appropriate this approach would be regarding other properties.
It certainly seams that as there is greater cross-pollination between specifications, this kind of situation is likely to become more prevalent and a sustainable solution would be nice.
SebastianZ commentedon Nov 22, 2019
@simlawr That solution would somewhat cleanly solve the current issue regarding the
-gapproperties, as authors can easily understand it.Though I believe it doesn't scale because it means that for every new property that is shared between different contexts, there needs to be an alias introduced only for the purpose of feature detection. That burdens authors, as they have to remember the aliases when doing feature detection, implementors, as they have to implement the aliases only applying in certain contexts, spec. authors because they will have to remember to add those aliases when the property is used in different contexts, and documentation writers because they will also have to cover those aliases.
Unfortunately, I don't have a better solution for this. There is probably no automated way of doing this kind of feature detection.
Sebastian
Dan503 commentedon Apr 29, 2020
I really like Rachel's original suggestion although I would change it to "with" rather than "in" because you are more looking for a generic relationship between the 2 rather than a parent/child relationship.
It doesn't sound that impossible for the computer to recognise.
The browser would need to check if both of the following conditions are true:
If not then it returns
false.I am probably grossly simplifying the problem though. 😅
foolip commentedon Oct 27, 2020
In the case of flex gap specifically, is there any workaround for web developers to detect support for it? It's only recently shipped in Chrome and even more recently landed in Safari Technology Preview, and without feature detection people will need to wait for another 3 years or so to be able to simply assume it will work.
Dan503 commentedon Oct 27, 2020
Yes, there is but you have to use JS to detect it.
The following is based on this blog post:
https://ishadeed.com/article/flexbox-gap/
28 remaining items
stof commentedon Jan 12, 2024
Even if some browsers already support gap in flexbox without this feature detection, it would still be great to add a keyword for it.
As @romainmenke pointed out earlier, making existing versions of browser apply the fallback implementation with margins instead of using gap would often be acceptable, while still using gap for newest browsers and supporting a fallback for browsers without support for gap.
WebMechanic commentedon Jan 21, 2024
so I did not follow all the threads surrounding this or have read all minutes... I would be a user of this feature.
FWIW a syntax like
@supports feature(gap-on-display-flex)seem very counter intuitive and artificial in nature.It requires learning a (albeit limited) vocabulary to describe a problem, requires maintenance (in code and documentation) and specific documentation (lists) that would be hard to "guess" where to find. And whomever writes a blog post would also need to mention these magic keywords and all existing documentation on either the main or supplemental feature would be outdated.
Some generic feature test on the other hand like
@supports (gap: 1px) with (display: flex)seems more intuitive to me as it describes spot on the query of a problem that needs solving: does this work in the context of that?Thank you folks for your great work!
Have a nice time.
dbaron commentedon Jan 29, 2024
I think the basic reason not to do this is that there are probably a few thousand different options for the things on either side of the
within your proposal (different CSS properties, plus different generations of values added to those properties over time), which means there are a few million possiblewithcombinations. There's no ready source of data for the answer to those few millions of questions, so we (both the working group and implementors) would need to sit down and decide what the correct answer to each one is, ensure engines implement them correctly, and test them.If you combine that with the reality that there's a single digit number of these questions that we know are much more interesting than all the others, it seems much more solvable to deal with the single digit number of questions than with a few million questions.
WebMechanic commentedon Jan 30, 2024
@dbaron Thanks for your reply! I believe this makes sense :-)
My thinking was: the CSS engine should-would eventually know anyway if any property is "valid" within a specific context as it has to render it at some point and decide if it knows what it's about. And we can already have a gazillion warnings abourt invalid / unsupported properties in the console -- like vendor prefixed stuff.
But maybe this "path" is too expensive to follow in the initial parser level.
Have a nice time.
JoshuaLindquist commentedon Feb 2, 2024
Is there a reason the previous suggestions list the display type last? It seems more intuitive to me to have keywords that list the display type first and then follow it with the requested feature.
feature(flex-gap)Using
feature()is not my favorite solution.Since the current resolution is to implement keywords only on rare occasions (1 a year, per the log) and to make it easy to educate everyone to use with minimal confusion, I think it would be better to use a keyword that screams "this is a very special use case" rather than a generic term like
feature(). I think usingfeature()sets a reasonable expectation that you can check for any set of CSS features, and it will cause confusion when it doesn't work that way.Even something like
case()orkeyword()or justkey()seems better to me (though I don't love any of those).yisibl commentedon May 30, 2024
I'm concerned that one-off keywords will greatly increase the burden on the author's memory.
I have a
@featureproposal, This is flexible enough to essentially do what JS currently does to create empty elements for detection. But I am not sure it's feasible.dbaron commentedon May 30, 2024
I think @yisibl's proposal in #3559 (comment) has the issues described in #3559 (comment) .
[css-conditional-5] Add the named-feature() function.
fantasai commentedon Jan 15, 2026
Not really. Whether a property has an effect in a specific context depends on whether we wrote code in that module to handle it. There's judgement of all properties, it's just that at the point in the layout algorithm where you need to check a property, you check it. For example in flex layout, support for gaps looks like including the value of the gap property in various equations scattered throughout the flex layout code. As dbaron notes, this is not something that the engine has a database of and can query.
Add experimental support for named-feature() function in CSS @supports.
Add experimental support for named-feature() function in CSS @supports.
Bug 2015505 [wpt PR 57653] - Add experimental support for named-featu…
Bug 2015505 [wpt PR 57653] - Add experimental support for named-featu…