Skip to content

[css-conditional] Behavior of @supports(at-rule(@import)) #11116

Closed

Description

@andruud

How does at-rule() handle rules with positional requirements? For example:

@supports at-rule(@charset) {}
@supports at-rule(@import) {}

This was discussed during #2463, and there were opinions on it, but there was no conclusion.

Activity

  1. bleper commented on Oct 31, 2024

    @bleper

    The case of @charset is interesting, since according to the specification it is not an at-rule, although it usually looks and is perceived by authors as such. Would it be useful to add some special handling for this?

  2. bramus commented on Nov 1, 2024

    @bramus
    Contributor

    In #6966 (comment) I suggested to allow authors to either test for an at-rule’s name or an actual full at-rule.

    That suggestion would also cover this case, as you could then check for someting like @import … layer(…) and such.

  3. kbabbitt commented on Jul 11, 2025

    @kbabbitt
    Collaborator

    I don't see any reason why we shouldn't let authors test for support of @import. It might not be useful in @supports itself because you can't then condition an @import on it, but I could see it being useful either in CSS.supports(...) or @import ... supports(...).

    For @charset I think the same principle applies, except for what @bleper pointed out, which is that @charset technically is not an at-rule. I can see four ways of dealing with that situation:

    1. Accept the situation as-is, which would make it not supported when tested with at-rule() since there is no at-rule named @charset. I don't like this option because it seems to prioritize architectural purity over author utility, but I could be swayed to it with a strong enough argument for why other options wouldn't work.
    2. In the context of at-rule(), pretend that @charset is an at-rule. This is author-friendly and less churn on existing specs, but it could lead to confusion in the other direction if someone reads the spec for @charset and concludes it's not testable in at-rule().
    3. Adjust the @supports grammar to make @charset testable in a way that bypasses the situation. Some of the straw examples in [css-conditional-5] Feature detection for descriptors #2463 had no at-rule() function at all but rather tested things directly in @supports just like property:value pairs, e.g. @supports (@charset). From reading the discussion minutes, I got the impression that some folks preferred having a function and others didn't object, so that's what the group resolved on, but we could revisit that decision.
    4. Change the specification of @charset so that it would be considered an at-rule. Based on my read of the spec, I'm imagining this as something like a "restricted at-rule" that preserves the existing syntax constraints but simply removes the technicality that it's not an at-rule for sake of clarity.

    Options 2-4 also raise another question: If we accept the proposal in #6966 to add a third form that takes an entire at-rule, for @charset would we apply the same strict parsing as for actual use at the top of a stylesheet? I would think "yes," because otherwise an author might get a "supported" answer if e.g. there there's extra whitespace present in their supports condition, but then if they copy-paste that condition to the top of a new stylesheet suddenly it wouldn't work, and it would not be clear why.

  4. tabatkins commented on Jul 15, 2025

    @tabatkins
    Member

    Given that we're never extending or changing @charset in any way (the correct solution is "just use UTF-8, you maniac"), I don't care particularly much whether it's supported or not in @supports. Purely on cost-benefit, I think it's worth leaving it out; more or less nobody even thinks of @charset in the first place, and there is literally nothing you can do in response to any such test (since it's processed solely in a pre-processing step before parsing even occurs).

    If there is ever a use-case for testing whether a given charset is supported by the browser in CSS, I'd be fine with defining a charset() testing function, but I just don't see how it's worth anyone's time to add special-case handling of @charset in @supports itself.

  5. kbabbitt commented on Aug 4, 2025

    @kbabbitt
    Collaborator

    Tagging for discussion at the upcoming F2F.

    Proposal: @import is testable but @charset is not.

    Details in the explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/AtRuleFeatureDetection/explainer.md#non-goals

  6. moved this from FTF agenda items to Wednesday Morning in CSSWG August 2025 meeting agendaon Aug 18, 2025
  7. css-meeting-bot commented on Aug 20, 2025

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-conditional] Behavior of @supports(at-rule(@import)), and agreed to the following:

    • RESOLVED: at-rule(@charset) is invalid, but at-rule(@import) is allowed
    The full IRC log of that discussion <TabAtkins> kbabbitt: This is about what at-rules can be tested by at-rule(), partiuclarly those with positional requirements
    <TabAtkins> kbabbitt: anders asked about @charset and @import
    <TabAtkins> kbabbitt: proposed resolution is @import is testable, @charset is not, because @charset isn't actually an at-rule, it just looks like one
    <TabAtkins> kbabbitt: from Tab's epxlanation, @charset is a legacy feature that authors shoudln't be using anymore
    <lea> q?
    <lea> q+
    <TabAtkins> astearns: so proposed resolution is at-rule(@charset) is not testable, but at-rule(@import) is?
    <astearns> ack lea
    <TabAtkins> lea: does this apply just to at-rule(), or to the larger @supports-condition thing?
    <TabAtkins> kbabbitt: this just applies to at-rule() right now
    <TabAtkins> astearns: objections?
    <TabAtkins> RESOLVED: at-rule(@charset) is invalid, but at-rule(@import) is allowed
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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions