Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cdoublev opened this issue Jan 31, 2022 · 0 comments
Closed

Comments

@cdoublev
Copy link
Collaborator

cdoublev commented Jan 31, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant