Skip to content

[css-namespaces-3] Clarify the validity of @namespace preceding @import #7001

Closed
@cdoublev

Description

@cdoublev

Any @namespace rules must follow all @charset and @import rules and precede all other non-ignored at-rules and style rules in a style sheet. [...]

A syntactically invalid @namespace rule (whether malformed or misplaced) must be ignored.

https://drafts.csswg.org/css-namespaces-3/#syntax

In the following case, both Chrome/Firefox do not ignore @namespace but ignore the @import:

<style>
  @namespace test "http://www.w3.org/2000/svg";
  @import "./stylesheet.css"; /* Declares `div { color: green }` */
  test|svg {
    background-color: red;
  }
</style>
<div>Green?</div>
<svg width="500" height="500"></svg>

A strict interpretation would be that @namespace is misplaced and should be ignored.

Also, I did not test the current UA behavior with @namespace preceding @charset, but I understood that all other rules following the first @charset rules are ignored, therefore it could be allowed.

User agents must ignore any @charset rule not at the beginning of the style sheet. When user agents detect the character encoding using the BOM and/or the @charset rule, they should follow the following rules:

Except as specified in these rules, all @charset rules are ignored.

https://drafts.csswg.org/css2/#charset%E2%91%A0

EDIT: @import would be invalid (see below) and ignored, @charset not at the beginning of the style sheet is also ignored (see above), and @namespace is valid if it precedes all other non-ignored at-rules, ie. any valid rules that is not @import (again, @charset following @namespace is always invalid).

Any @import rules must precede all other valid at-rules and style rules in a style sheet (ignoring @charset), or else the @import rule is invalid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions