Skip to content

[css-cascade] Clarify when an @import rule is valid #5313

Closed
@andreubotella

Description

@andreubotella

The definition of when an @import rule is valid is:

Any @import rules must precede all other at-rules and style rules in a style sheet (besides @charset, which must be the first thing in the style sheet if it exists), or else the @import rule is invalid.

Given that in CSS3 @charset is no longer a rule, it's not clear what the interpretation of that sentence would be when the parser finds an invalid rule named @charset that hasn't been interpreted as a fallback encoding marker by the input byte stream.

I've run a few tests, and the behavior of Firefox, Chrome and Epiphany / GNOME Web (a Webkit representative, since I don't have access to Mac or iOS machines) match: an @import rule is valid if every rule before it in the stylesheet is either invalid or an @import rule.

And this behavior is in fact consistent with this text in css-syntax:

If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error. Discard that rule.

But in any case, the language in css-cascade should probably be updated to not refer to @charset as a rule and to clarify this, even if the correct behavior can be reasoned out from other specs.

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