CINXE.COM

CSS Namespaces Module

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang=en> <head><meta content="text/html; charset=utf-8" http-equiv=Content-Type> <title>CSS Namespaces Module</title> <link href=default.css rel=stylesheet type="text/css"> <link href="https://www.w3.org/StyleSheets/TR/W3C-REC" rel=stylesheet type="text/css"> <body> <div class=head> <!--begin-logo--> <p><a href="https://www.w3.org/"><img alt=W3C height=48 src="https://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo--> <h1>CSS Namespaces Module</h1> <h2 class="no-num no-toc" id=longstatus-date>W3C Recommendation 29 September 2011</h2> <dl> <dt>This version: <dd><a href="https://www.w3.org/TR/2011/REC-css3-namespace-20110929/">http://www.w3.org/TR/2011/REC-css3-namespace-20110929/</a> <dt>Latest version: <dd><a href="https://www.w3.org/TR/css3-namespace/">http://www.w3.org/TR/css3-namespace/</a> <dt>Previous version: <dd><a href="https://www.w3.org/TR/2011/PR-css3-namespace-20110811/">http://www.w3.org/TR/2011/PR-css3-namespace-20110811/</a> <dt>Editors: <dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> <dd><a href="https://annevankesteren.nl/about">Anne van Kesteren</a>, Opera Software ASA <dt>Previous Editors: <dd>Peter Linss, Netscape Communications <dd>Chris Lilley, W3C </dl> <p>Please refer to the <a href="https://www.w3.org/Style/2011/REC-css3-namespace-20110929-errata.html"><strong>errata</strong></a> for this document, which may include some normative corrections.</p> <p>See also <a href="https://www.w3.org/2003/03/Translations/byTechnology?technology=css3-namespace"> <strong>translations</strong></a>.</p> <!--begin-copyright--> <p class="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> &copy; 2011 <a href="https://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>&reg;</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.eu/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p> <!--end-copyright--> <hr title="Separator for header"> </div> <h2 class="no-num no-toc" id=abstract>Abstract</h2> <p>This CSS Namespaces module defines the syntax for using namespaces in CSS. It defines the <code>@namespace</code> 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. <h2 class="no-num no-toc" id=status>Status of this document</h2> <!--begin-status--> <p><em>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 <a href="https://www.w3.org/TR/">W3C technical reports index at http://www.w3.org/TR/.</a></em> <p>This document was produced by the <a href="https://www.w3.org/Style/CSS/members">CSS Working Group</a> as a <a href="https://www.w3.org/Consortium/Process/tr#RecsPR">Proposed Recommendation.</a> <p>A W3C Recommendation is a mature document that has been widely reviewed and has been shown to be implementable. W3C encourages everybody to implement this specification. Comments may be sent to the (<a href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public mailing list <a href="mailto:www-style@w3.org?Subject=%5Bcss3-namespace%5D%20PUT%20SUBJECT%20HERE">www-style@w3.org</a> (see <a href="https://www.w3.org/Mail/Request">instructions</a>). When sending e-mail, please put the text &#8220;css3-namespace&#8221; in the subject, preferably like this: &#8220;[<!---->css3-namespace<!---->] <em>&hellip;summary of comment&hellip;</em>&#8221; <p>This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.</p> <p>This document was produced by a group operating under the <a href="https://www.w3.org/Consortium/Patent-Policy-20040205/">5&nbsp;February 2004 W3C Patent Policy</a>. W3C maintains a <a href="https://www.w3.org/2004/01/pp-impl/32061/status" rel=disclosure>public list of any patent disclosures</a> 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 <a href="https://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure"> section&nbsp;6 of the W3C Patent Policy</a>.</p> <!--end-status--> <p>A CSS Namespace <a href="https://www.w3.org/Style/CSS/Test/">Test Suite</a> has been developed during the Candidate Recommendation phase of this CSS Namespaces specification. An <a href="/Style/CSS/Test/CSS3/Namespace/20090210/reports/implement-report.html">implementation report</a> is also available. <p id=changes>This document is the same as the previous, Proposed Recommendation version, except for editorial changes to the front matter, and updating of references. <h2 class="no-num no-toc" id=contents>Table of Contents</h2> <!--begin-toc--> <ul class=toc> <li><a href="#intro"><span class=secno>1. </span>Introduction</a> <li><a href="#conformance"><span class=secno>2. </span>Conformance</a> <ul class=toc> <li><a href="#terminology"><span class=secno>2.1. </span>Terminology</a> </ul> <li><a href="#declaration"><span class=secno>3. </span>Declaring namespaces: the <code>@namespace</code> rule</a> <ul class=toc> <li><a href="#syntax"><span class=secno>3.1. </span>Syntax</a> <li><a href="#scope"><span class=secno>3.2. </span>Scope</a> <li><a href="#prefixes"><span class=secno>3.3. </span>Declaring Prefixes</a> </ul> <li><a href="#css-qnames"><span class=secno>4. </span>CSS Qualified Names</a> <li class=no-num><a href="#acknowledgments">Acknowledgments</a> <li class=no-num><a href="#references">References</a> <ul class=toc> <li class=no-num><a href="#normative-references">Normative references</a> <li class=no-num><a href="#informative-references">Informative references</a> </ul> </ul> <!--end-toc--> <div> <h2 id=intro><span class=secno>1. </span>Introduction</h2> <p><em>This section is non-normative.</em></p> <p>This CSS Namespaces module defines syntax for using namespaces in CSS. It defines the <code>@namespace</code> 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 (<a href="#SELECT" rel=biblioentry>[SELECT]<!--{{SELECT}}--></a>), that references the syntax defined in the CSS Namespaces module. <p>Note that a CSS client that does not support this module will (if it properly conforms to <a href="https://www.w3.org/TR/CSS21/syndata.html#parsing-errors">CSS's forward-compatible parsing rules</a>) ignore all <code>@namespace</code> 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.</p> </div> <div> <h2 id=conformance><span class=secno>2. </span>Conformance</h2> <p>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.</p> <p>Conformance to CSS Namespaces is defined for two classes: <dl> <dt><dfn id=style-sheet>style sheet</dfn> <dd>A <a href="https://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS style sheet</a> (or a complete unit of another host language that normatively references CSS Namespaces). <dt><dfn id=interpreter>interpreter</dfn> <dd>Someone or something that interprets the semantics of a style sheet. (CSS <a href="https://www.w3.org/TR/CSS21/conform.html#user-agent">user agents</a> fall under this category.) </dl> <p>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. <a href="#RFC2119" rel=biblioentry>[RFC2119]<!--{{!RFC2119}}--></a></p> <p>Examples in this specification are introduced with the words "for example" or are set apart from the normative text with <code>class="example"</code>, like this: <div class=example> <p>This is an example of an informative example.</p> </div> <p>Informative notes begin with the word "Note" and are set apart from the normative text with <code>class="note"</code>, like this: <p class=note>Note, this is an informative note.</p> <h3 id=terminology><span class=secno>2.1. </span>Terminology</h3> <p>Besides terms introduced by this specification, CSS Namespaces uses the terminology defined in Namespaces in XML 1.0. <a href="#XML-NAMES" rel=biblioentry>[XML-NAMES]<!--{{!XML-NAMES}}--></a> 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.</p> <p>In CSS Namespaces a namespace name consisting of the empty string is taken to represent the null namespace or lack of a namespace.</p> <div class=example> <p>For example, given the namespace declarations:</p> <pre>@namespace empty ""; <!-- -->@namespace "";</pre> <p>The <a href="https://www.w3.org/TR/css3-selectors/#type-selectors">type selectors</a> <code>elem</code>, <code>|elem</code>, and <code>empty|elem</code> are equivalent.</p> </div> </div> <div> <h2 id=declaration><span class=secno>3. </span>Declaring namespaces: the <code>@namespace</code> rule</h2> <p>The <code>@namespace</code> <a href="https://www.w3.org/TR/CSS21/syndata.html#at-rules">at-rule</a> 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 <a href="#css-qnames">CSS qualified names</a> defined below.</p> <div class=example> <pre>@namespace "http://www.w3.org/1999/xhtml"; <!-- -->@namespace svg "http://www.w3.org/2000/svg";</pre> <p>The first rule declares a default namespace <code>http://www.w3.org/1999/xhtml</code> to be applied to names that have no explicit namespace component.</p> <p>The second rule declares a namespace prefix <code>svg</code> that is used to apply the namespace <code>http://www.w3.org/2000/svg</code> where the <code>svg</code> namespace prefix is used.</p> </div> <p id=expanded-name-match>In CSS Namespaces, as in Namespaces in XML 1.0, the prefix is merely a syntactic construct; it is the <em><dfn id=expanded-name>expanded name</dfn></em> (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.</p> <div class=example> <p>For example, given the following XML document:</p> <pre><!-- -->&lt;qml:elem xmlns:qml="http://example.com/q-markup">&lt;/qml:elem><!-- --></pre> <p>and the following <code>@namespace</code> declarations at the beginning of a CSS file:</p> <pre><!-- -->@namespace Q "http://example.com/q-markup"; <!---->@namespace lq "http://example.com/q-markup";<!-- --></pre> <p>The selectors <code>Q|elem</code> and <code>lq|elem</code> in that CSS file would both match the element <code>&lt;qml:elem&gt;</code>. (The selector <code>qml|elem</code> would be invalid.)</p> </div> <h3 id=syntax><span class=secno>3.1. </span>Syntax</h3> <p>The syntax for the <code>@namespace</code> rule is as follows (using the notation from the <a href="https://www.w3.org/TR/CSS21/grammar.html">Grammar appendix of CSS 2.1</a> <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>):</p> <pre><!-- -->namespace <!-- --> : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S* <!-- --> ; <!-- -->namespace_prefix <!-- --> : IDENT <!-- --> ;<!-- --></pre> <p>with the new token:</p> <pre>@{N}{A}{M}{E}{S}{P}{A}{C}{E} {return NAMESPACE_SYM;}</pre> <p>Any <code>@namespace</code> 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 <code>[ namespace [S|CDO|CDC]* ]*</code> immediately after <code>[ import [S|CDO|CDC]* ]*</code> in the <code>stylesheet</code> grammar.</p> <p>A syntactically invalid <code>@namespace</code> rule (whether malformed or misplaced) must be <a href="https://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>. A CSS <a href="https://www.w3.org/TR/CSS21/conform.html#style-sheet">style sheet</a> containing an invalid <code>@namespace</code> rule is not a <a href="https://www.w3.org/TR/CSS21/conform.html#valid-style-sheet">valid style sheet</a>.</p> <p>A URI string parsed from the <code>URI</code> syntax must be treated as a literal string: as with the <code>STRING</code> syntax, no URI-specific normalization is applied.</p> <p>All strings&#8212;including the empty string and strings representing invalid URIs&#8212;are valid namespace names in <code>@namespace</code> declarations.</p> <h3 id=scope><span class=secno>3.2. </span>Scope</h3> <p>The namespace prefix is declared only within the style sheet in which its <code>@namespace</code> 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.</p> <h3 id=prefixes><span class=secno>3.3. </span>Declaring Prefixes</h3> <p>A <dfn id=namespace-prefix>namespace prefix</dfn>, 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, <a href="https://www.w3.org/TR/CSS21/syndata.html#counter">like CSS counter names</a>, case-sensitive.</p> <!-- They do not, however, distinguish between equivalent canonical Unicode representations. Essentially, an <code>@namespace</code> declaration declares all prefixes that map to the same NFC representation as the given prefix to the same namespace name. (See [[!UNICODE]] for the definition of NFC normalization.) --> <p>If in the namespace declaration the namespace prefix is omitted, then the namespace so declared is the default namespace. The <dfn id=default-namespace>default namespace</dfn> 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 <a href="#XML-NAMES" rel=biblioentry>[XML-NAMES]<!--{{!XML-NAMES}}--></a>, in Selectors <a href="#SELECT" rel=biblioentry>[SELECT]<!--{{SELECT}}--></a> the default namespace applies to type selectors&#8212;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.</p> <p class=note>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.</p> <p>If a namespace prefix or default namespace is declared more than once only the last declaration shall be used. Declaring a namespace prefix or default namespace more than once is nonconforming.</p> </div> <div> <h2 id=css-qnames><span class=secno>4. </span>CSS Qualified Names</h2> <p>A <dfn id=css-qualified-name>CSS qualified name</dfn> 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" (<code>|</code>, 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 (<code>*</code>, U+002A) as a wildcard prefix to indicate a name in any namespace, including no namespace.</p> <div class=example> <p>Given the namespace declarations:</p> <pre>@namespace toto "http://toto.example.org"; <!-- -->@namespace "http://example.com/foo";</pre> <p>In a context where the default namespace applies</p> <dl> <dt><code>toto|A</code> <dd>represents the name <code>A</code> in the <code>http://toto.example.org</code> namespace. <dt><code>|B</code> <dd>represents the name <code>B</code> that belongs to no namespace. <dt><code>*|C</code> <dd>represents the name <code>C</code> in any namespace, including no namespace. <dt><code>D</code> <dd>represents the name <code>D</code> in the <code>http://example.com/foo</code> namespace. </dl> </div> <p>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 (<code>wqname</code>) and for qualified names that disallow wildcard prefixes (<code>qname</code>). (The syntax uses notation from the <a href="https://www.w3.org/TR/CSS21/grammar.html">Grammar appendix of CSS 2.1</a>. <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> Note this means that comments, but not white space, are implicitly allowed between tokens.):</p> <pre><!-- -->qname_prefix <!-- --> : [namespace_prefix]? '|' <!-- --> ; <!-- -->wqname_prefix <!-- --> : namespace_prefix? '|' <!-- --> | '*' '|' <!-- --> ;<!-- --></pre> <p>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, <a href="https://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.</p> <div class=example> <p>For example, the Selectors module <a href="#SELECT" rel=biblioentry>[SELECT]<!--{{SELECT}}--></a> defines a type selector with an undeclared namespace prefix to be an invalid selector, and CSS <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> requires rule sets with an invalid selector to be completely ignored.</p> </div> </div> <h2 class=no-num id=acknowledgments>Acknowledgments</h2> <p>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&aring;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&ouml;ern H&ouml;hrmann, and Lachlan Hunt for their comments. <h2 class=no-num id=references>References</h2> <h3 class=no-num id=normative-references>Normative references</h3> <!--begin-normative--> <!-- Sorted by label --> <dl class=bibliography> <dt style="display: none"><!-- keeps the doc valid if the DL is empty --> <!----> <dt id=CSS21>[CSS21] <dd>Bert Bos; et al. <a href="https://www.w3.org/TR/2011/REC-CSS2-20110607"><cite>Cascading Style Sheets Level 2 Revision 1 (CSS&#160;2.1) Specification.</cite></a> 7 June 2011. W3C Recommendation. URL: <a href="https://www.w3.org/TR/2011/REC-CSS2-20110607">http://www.w3.org/TR/2011/REC-CSS2-20110607</a> </dd> <!----> <dt id=RFC2119>[RFC2119] <dd>S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt"><cite>Key words for use in RFCs to Indicate Requirement Levels.</cite></a> Internet RFC 2119. URL: <a href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a> </dd> <!----> <dt id=XML-NAMES>[XML-NAMES] <dd>Tim Bray; et al. <a href="https://www.w3.org/TR/2009/REC-xml-names-20091208/"><cite>Namespaces in XML 1.0 (Third Edition).</cite></a> 8 December 2009. W3C Recommendation. URL: <a href="https://www.w3.org/TR/2009/REC-xml-names-20091208/">http://www.w3.org/TR/2009/REC-xml-names-20091208/</a> </dd> <!----> </dl> <!--end-normative--> <h3 class=no-num id=informative-references>Informative references</h3> <!--begin-informative--> <!-- Sorted by label --> <dl class=bibliography> <dt style="display: none"><!-- keeps the doc valid if the DL is empty --> <!----> <dt id=SELECT>[SELECT] <dd>Tantek &#199;elik; et al. <a href="https://www.w3.org/TR/2011/REC-css3-selectors-20110929"><cite>Selectors Level 3.</cite></a> 29 September 2011. W3C Recommendation. URL: <a href="https://www.w3.org/TR/2011/REC-css3-selectors-20110929">http://www.w3.org/TR/2011/REC-css3-selectors-20110929</a> </dd> <!----> </dl> <!--end-informative--> <script src="https://www.w3.org/scripts/TR/fixup.js"></script></html> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-declaration:"~/SGML/HTML4.decl" sgml-default-doctype-name:"html" sgml-minimize-attributes:t sgml-nofill-elements:("pre" "style" "br") sgml-live-element-indicator:t sgml-omittag:nil sgml-shorttag:nil sgml-namecase-general:t sgml-general-insert-case:lower sgml-always-quote-attributes:t sgml-indent-step:nil sgml-indent-data:t sgml-parent-document:nil sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: -->

Pages: 1 2 3 4 5 6 7 8 9 10