1. Introduction
This section is non-normative.
This CSS Namespaces module defines syntax for using namespaces in CSS. It defines the @namespace rule for declaring a default namespace and for binding namespaces to namespace prefixes. It also defines a syntax for using those prefixes to represent namespace-qualified names. It does not define where such names are valid or what they mean: that depends on their context and is defined by a host language, such as Selectors ([SELECT]), that references the syntax defined in the CSS Namespaces module.
Note that a CSS client that does not support this module will (if it properly conforms to CSS’s forward-compatible parsing rules) ignore all @namespace rules, as well as all style rules that make use of namespace qualified names. The syntax of delimiting namespace prefixes in CSS was deliberately chosen so that these CSS clients would ignore the style rules rather than possibly match them incorrectly.
1.1. Terminology
Besides terms introduced by this specification, CSS Namespaces uses the terminology defined in Namespaces in XML 1.0. [XML-NAMES] However, the syntax defined here is not restricted to representing XML element and attribute names and may represent other kinds of namespaces as defined by the host language.
In CSS Namespaces a namespace name consisting of the empty string is taken to represent the null namespace or lack of a namespace.
@namespace empty ""; @namespace "";
The type selectors elem
, |elem
,
and empty|elem
are equivalent.
2. Declaring namespaces: the @namespace rule
The @namespace at-rule declares a namespace prefix and associates it with a given namespace name (a string). This namespace prefix can then be used in namespace-qualified names such as the CSS qualified names defined below.
@namespace "http://www.w3.org/1999/xhtml"; @namespace svg "http://www.w3.org/2000/svg";
The first rule declares a default namespace http://www.w3.org/1999/xhtml
to be applied to names that have no explicit namespace component.
The second rule declares a namespace prefix svg
that is used to apply the namespace http://www.w3.org/2000/svg
where the svg
namespace prefix is used.
In CSS Namespaces, as in Namespaces in XML 1.0, the prefix is merely a syntactic construct; it is the expanded name (the tuple of local name and namespace name) that is significant. Thus the actual prefixes used in a CSS style sheet, and whether they are defaulted or not, are independent of the namespace prefixes used in the markup and whether these are defaulted or not.
<qml:elem xmlns:qml="http://example.com/q-markup"></qml:elem>
and the following @namespace declarations at the beginning of a CSS file:
@namespace Q "http://example.com/q-markup"; @namespace lq "http://example.com/q-markup";
The selectors Q|elem and lq|elem in that CSS file
would both match the element <qml:elem>
.
(The selector qml|elem would be invalid, because CSS namespaces only recognize prefixes declared in CSS, not those declared by the document language.)
2.1. Syntax
The syntax for the @namespace rule is:
@namespace <namespace-prefix>? [ <string> | <url> ] ; <namespace-prefix> = <ident>
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.
For CSS syntax this adds [ namespace [SCDOCDC]* ]*
immediately after [ import [SCDOCDC]* ]*
in the stylesheet
grammar.
A syntactically invalid @namespace rule (whether malformed or misplaced) must be ignored. A CSS style sheet containing an invalid @namespace rule is not a valid style sheet.
A URI string parsed from the URI
syntax must be treated as a literal string:
as with the STRING
syntax,
no URI-specific normalization is applied.
All strings—including the empty string and strings representing invalid URIs—are valid namespace names in @namespace declarations.
2.2. Scope
The namespace prefix is declared only within the style sheet in which its