CSS Module: Namespaces

W3C Working Draft 28 August 2006

This version:
Latest version:
Previous version:
Elika J. Etemad
Previous Editors:
Peter Linss, Netscape Communications
Chris Lilley, W3C


This CSS module defines the syntax for using namespaces in CSS. It introduces the @namespace rule for declaring the default namespace and binding namespaces to namespace prefixes, and it 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/.

Publication as a Working Draft 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.

The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css3-namespace” in the subject, preferably like this: “[css3-namespace] …summary of comment…

This document was produced by the CSS Working Group (part of the Style Activity).

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.

This is a draft of a module of CSS (Cascading Style Sheets). It is derived with minimal change from the CSS3 Namespace Enhancements syntax proposal from 1999 with which the CSS WG has been in agreement for many years and which is already implemented in user agents. The material from that proposal found its way into drafts of [SELECT], [CSS3SYN] and [CSS3VAL]. [SELECT] is currently a Candidate Recommendation. Unfortunately, [CSS3SYN] has dependencies on (potentially) all other CSS3 modules and this, plus work on CSS2.1, has delayed the availability of this specification. To break the chain of dependencies and allow faster progress on the Recommendation track, the present module has been split out. It is primarily intended as a CSS module, though it could also be referenced by [SVG12] or indeed [CSS21].

Table of contents

1. Introduction

This section is informative.

This specification defines the syntax for using namespaces in CSS. It introduces the @namespace rule for declaring a default namespace and for binding namespaces to namespace prefixes. This specification also defines a syntax for using those prefixes in namespace-qualified names, but does not define where such names are valid or what they mean. The terminology used in this specification is that of [XML-NAMES11]. Do we really need this sentence?

It should be noted that a CSS client that does not support this module will (if it properly conforms to CSS 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 this specification alone, but can claim conformance to this specification if it satisfies the conformance requirements in this specification when implementing CSS or another host language that normatively references this specification.

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 (see [RFC2119]). 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 examples, notes, and sections explicitly marked as non-normative.

3. Declaring namespaces: the @namespace rule

The @namespace at-rule declares a namespace prefix and associates it with a given namespace (a string). This namespace prefix can then be used in namespace-qualified names such as those described in the Selectors Module [SELECT] or the Values and Units module [CSS3VAL].

@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 XML Namespaces [REC-XML-NAMES], the local prefix is merely a syntactic construct; it is the expanded name (the tuple of local name and namespace) 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.

3.1. Syntax

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

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

with the new token:

"@namespace"              {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 style sheet containing an invalid @namespace rule is non-conforming.

A URI string parsed from the url() syntax must be treated as a literal string: no URI-specific normalization is applied. For this reason the string syntax is recommended, and the url() syntax discouraged deprecated?.

3.2. Scope

The namespace prefix is declared only within the style sheet in which its @namespace rule appears, and not any style sheets imported by that style sheet, style sheets that import that style sheet, or 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.

If in the namespace declaration the namespace prefix is omitted, then the namespace so declared is the default namespace. The default namespace applies 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 [REC-XML-NAMES], in Selectors [SELECT] the default namespace applies to type selectors—but it does not apply to attribute selectors. There is no default 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.

Namespace prefixes are, like CSS property names, case-insensitive.

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

4. CSS Qualified Names

A 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. Some contexts 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

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

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


This draft borrows heavily from earlier drafts on CSS namespace support by Chris Lilley and by Peter Linss [CSS3NAMESPACE] 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 Ian Hickson, Bjöern Höhrmann, Anne van Kesteren, and L. David Baron for their comments.


Normative references

Bert Bos; et al. Cascading Style Sheets, level 2 revision 1. 11 April 2006. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2006/WD-CSS21-20060411

Informative references

Peter Linss. CSS Namespace Enhancements (Proposal). 25 June 1999. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/1999/06/25/WD-css3-namespace-19990625
L. David Baron. CSS3 module: Syntax. 13 August 2003. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2003/WD-css3-syntax-20030813
Håkon Wium Lie; Chris Lilley. CSS3 module: Values and Units. 13 July 2001. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2001/WD-css3-values-20010713
Tim Bray; Dave Hollander; Andrew Layman. Namespaces in XML. 14 January 1999. W3C Recommendation. URL: http://www.w3.org/TR/1999/REC-xml-names-19990114
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
Daniel Glazman; et al. Selectors. 13 November 2001. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2001/CR-css3-selectors-20011113
Dean Jackson. Scalable Vector Graphics (SVG) 1.2. 18 March 2004. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2004/WD-SVG12-20040318
Andrew Layman; et al. Namespaces in XML 1.1. 4 February 2004. W3C Recommendation. URL: http://www.w3.org/TR/2004/REC-xml-names11-20040204