W3C

CSS Namespaces Module

W3C Candidate Recommendation 23 May 2008

This version:
http://www.w3.org/TR/2008/CR-css3-namespace-20080523/
Latest version:
http://www.w3.org/TR/css3-namespace/
Previous version:
http://www.w3.org/TR/2008/WD-css3-namespace-20080215/
Editors:
Elika J. Etemad
Anne van Kesteren
Previous Editors:
Peter Linss, Netscape Communications
Chris Lilley, W3C

Abstract

This CSS Namespaces module defines the syntax for using namespaces in CSS. It defines the @namespace rule for declaring the default namespace and binding namespaces to namespace prefixes, and it also defines a syntax that other specifications can adopt for using those prefixes in namespace-qualified names.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was produced by the CSS Working Group as a Candidate Recommendation.

A Candidate Recommendation is a document that has been widely reviewed and ready for implementation. W3C encourages everybody to implement this specification and return comments to the (archived) public mailing list www-style@w3.org (see instructions). When sending e-mail, please put the text “css3-namespace” in the subject, preferably like this: “[css3-namespace] …summary of comment…

Publication as a Candidate Recommendation does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

For this specification to exit the CR stage, the following conditions shall be met:

  1. There must be at least two interoperable implementations. For the purposes of this criterion, we define the following terms:

    interoperable

    passing the respective test case(s) in the CSS test suite, or, if the implementation is not a Web browser, an equivalent test. Every relevant test in the test suite should have an equivalent test created if such a user agent (UA) is to be used to claim interoperability. In addition if such a UA is to be used to claim interoperability, then there must one or more additional UAs which can also pass those equivalent tests in the same way for the purpose of interoperability. The equivalent tests must be made publicly available for the purposes of peer review.

    implementation

    a user agent which:

    1. implements the specification.
    2. is available (i.e. publicly downloadable or available through some other public point of sale mechanism). This is the "show me" requirement.
    3. is shipped, or is a "nightly build" (i.e., a development version for the next release), but is not experimental (i.e., a version specifically designed to pass the test suite and not intended for daily usage going forward).
  2. A minimum of another three months of the CR period must elapse. That is, this specification will not exit CR before 23 August 2008. When the specification exits CR, an implementation report will be published. At this point, no such report exists.

  3. The specified technology must not be harmful for accessibility.

A CSS Namespace Test Suite will be developed during the Candidate Recommendation phase of this CSS Namespaces specification.

Comments on and subsequent changes since the last Working Draft are listed in the separate Disposition of Comments.

Table of contents

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.

2. Conformance

A document or implementation cannot conform to CSS Namespaces alone, but can claim conformance to CSS Namespaces if it satisfies the conformance requirements in this specification when implementing CSS or another host language that normatively references this specification.

Conformance to CSS Namespaces is defined for two classes:

style sheet
A CSS style sheet (or a complete unit of another host language that normatively references CSS Namespaces).
interpreter
Someone or something that interprets the semantics of a style sheet. (CSS user agents fall under this category.)

The conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification. All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word "Note" and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

2.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.

For example, given the namespace declarations:

@namespace empty "";
@namespace "";

The type selectors elem, |elem, and empty|elem are equivalent.

3. 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.

For example, given the following XML document:

<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.)

3.1 Syntax

The syntax for the @namespace rule is as follows (using the notation from the Grammar appendix of CSS 2.1 [CSS21]):

namespace
  : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S*
  ;
namespace_prefix
  : IDENT
  ;

with the new token:

@{N}{A}{M}{E}{S}{P}{A}{C}{E} {return NAMESPACE_SYM;}

Any @namespace rules must follow all @charset and @import rules and precede all other non-ignored at-rules and rule sets in a style sheet. For CSS syntax this adds [ namespace [S|CDO|CDC]* ]* immediately after [ import [S|CDO|CDC]* ]* 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 itself invalid.

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.

3.2 Scope

The namespace prefix is declared only within the style sheet in which its @namespace rule appears. It is not declared in any style sheets importing or imported by that style sheet, nor in any other style sheets applying to the document.

3.3 Declaring Prefixes

A namespace prefix, once declared, represents the namespace for which it was declared and can be used to indicate the namespace of a namespace-qualified name. Namespace prefixes are, like CSS counter names, case-sensitive.

If in the namespace declaration the namespace prefix is omitted, then the namespace so declared is the default namespace. The default namespace may apply to names that have no explicit namespace prefix: modules that employ namespace prefixes must define in which contexts the default namespace applies. For example, following [XML-NAMES], in Selectors [SELECT] the default namespace applies to type selectors—but it does not apply to attribute selectors. There is no default value for the default namespace: modules that assign unqualified names to the default namespace must define how those unqualified names are to be interpreted when no default namespace is declared.

Note that using default namespaces in conjunction with type selectors can cause UAs that support default namespaces and UAs that don't support default namespaces to interpret selectors differently. See Namespaces and down-level clients in the Selectors module [SELECT] for details.

If a namespace prefix or default namespace is declared more than once only the last declaration shall be used.

4. CSS Qualified Names

A CSS qualified name is a name explicitly located within (associated with) a namespace. To form a qualified name in CSS syntax, a namespace prefix that has been declared within scope is prepended to a local name (such as an element or attribute name), separated by a "vertical bar" (|, U+007C). The prefix, representing the namespace for which it has been declared, indicates the namespace of the local name. The prefix of a qualified name may be omitted to indicate that the name belongs to no namespace, i.e. that the namespace name part of the expanded name has no value. Some contexts (as defined by the host language) may allow the use of an asterisk (*, U+002A) as a wildcard prefix to indicate a name in any namespace, including no namespace.

Given the namespace declarations:

@namespace toto "http://toto.example.org";
@namespace "http://example.com/foo";

In a context where the default namespace applies

toto|A
represents the name A in the http://toto.example.org namespace.
|B
represents the name B that belongs to no namespace.
*|C
represents the name C in any namespace, including no namespace.
D
represents the name D in the http://example.com/foo namespace.

The syntax for the portion of a CSS qualified name before the local name is given below, both for qualified names that allow wildcard prefixes (wqname) and for qualified names that disallow wildcard prefixes (qname). (The syntax uses notation from the Grammar appendix of CSS 2.1 [CSS21]):

qname_prefix
  : [namespace_prefix]? '|'
  ;
wqname_prefix
  : namespace_prefix? '|'
  | '*' '|'
  ;

CSS qualified names can be used in (for example) selectors and property values as described in other modules. Those modules must define handling of namespace prefixes that have not been properly declared. Such handling should treat undeclared namespace prefixes as a parsing error that will cause the selector or declaration (etc.) to be considered invalid and, in CSS, ignored.

For example, the Selectors module [SELECT] defines a type selector with an undeclared namespace prefix to be an invalid selector, and CSS [CSS21] requires rule sets with an invalid selector to be completely ignored.

Acknowledgments

This draft borrows heavily from earlier drafts on CSS namespace support by Chris Lilley and by Peter Linss and early (unpublished) drafts on CSS and XML by Håkon Lie and Bert Bos, and XML Namespaces and CSS by Bert Bos and Steven Pemberton. Many current and former members of the CSS Working Group have contributed to this document. Discussions on www-style@w3.org and in other places have also contributed ideas to this specification. Special thanks goes to L. David Baron, Karl Dubost, Ian Hickson, Bjöern Höhrmann, and Lachlan Hunt for their comments.

References

Normative references

[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 19 July 2007. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2007/CR-CSS21-20070719
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
[XML-NAMES]
Tim Bray; et al. Namespaces in XML 1.0 (Second Edition). 16 August 2006. W3C Recommendation. URL: http://www.w3.org/TR/2006/REC-xml-names-20060816

Informative references

[SELECT]
Daniel Glazman; Tantek Çelik; Ian Hickson. Selectors. 15 December 2005. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2005/WD-css3-selectors-20051215