Skip to content

[css-conditional] testing support of properties and values with partial implementations #3559

Open

Description

@rachelandrew

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

Activity

  1. AmeliaBR commented on Jan 26, 2019

    @AmeliaBR
    Contributor

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

  2. nigelmegitt commented on Jan 28, 2019

    @nigelmegitt

    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.

  3. rachelandrew commented on Jan 28, 2019

    @rachelandrew
    ContributorAuthor

    "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.

  4. tabatkins commented on Jan 29, 2019

    @tabatkins
    Member

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

  5. jonjohnjohnson commented on Jan 30, 2019

    @jonjohnjohnson

    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)

    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...

    @dbaron #3051 (comment)

    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.

  6. tabatkins commented on Feb 2, 2019

    @tabatkins
    Member

    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.

  7. simlawr commented on Feb 15, 2019

    @simlawr

    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.

  8. SebastianZ commented on Nov 22, 2019

    @SebastianZ
    Contributor

    @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.

    Sebastian

  9. Dan503 commented on Apr 29, 2020

    @Dan503

    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. 😅

  10. foolip commented on Oct 27, 2020

    @foolip
    Member

    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.

  11. Dan503 commented on Oct 27, 2020

    @Dan503

    In the case of flex gap specifically, is there any workaround for web developers to detect support for it?

    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/

    // Set up a cache to prevent a DOM element from getting created for every use of the function
    let isSupported;
    
    function checkFlexGapSupport() {
            // Use the cached value if it has been defined
    	if (isSupported !== undefined) {
    		return isSupported
    	}
    
    	// Create a flex container with row-gap set
    	const flex = document.createElement('div')
    	flex.style.display = 'flex'
    	flex.style.flexDirection = 'column'
    	flex.style.rowGap = '1px'
    	flex.style.position = 'absolute'
    
    	// Create two, elements inside it
    	flex.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-gap
    	isSupported = flex.scrollHeight === 1
    
            // Remove element from the DOM after you are done with it
    	flex.parentNode.removeChild(flex)
    
    	return isSupported
    }
  12. 28 remaining items

  13. stof commented on Jan 12, 2024

    @stof

    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.

  14. WebMechanic commented on Jan 21, 2024

    @WebMechanic

    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.

  15. dbaron commented on Jan 29, 2024

    @dbaron
    Member

    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.

  16. WebMechanic commented on Jan 30, 2024

    @WebMechanic

    @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.

  17. JoshuaLindquist commented on Feb 2, 2024

    @JoshuaLindquist

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

  18. yisibl commented on May 30, 2024

    @yisibl
    Contributor

    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.

    @feature --align-content-on-block {
    	display: block;
    	align-content: center;
    }
    
    @supports --align-content-on-block {
    	.foo { /*  do something */ }
    }
    
    @feature --detecting-at-rule {
    	@container style(--foo: true) {}
    }
  19. dbaron commented on May 30, 2024

    @dbaron
    Member

    I think @yisibl's proposal in #3559 (comment) has the issues described in #3559 (comment) .

  20. fantasai commented on Jan 15, 2026

    @fantasai
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo