CSS Namespace Proposal This is now obsolete as the W3C have: a. used a similar syntax for the XML namespace support b. stopped writing huge specs and turned to modularisation for CSS3. But, for historical interest... INTRODUCTION ------------ There are currently five different languages that all use the CSS syntax: CSS itself [1], the styling part of the SVG [2] proposal, the CAS (Action Sheets) proposal [3], the IE CSS extensions and the internal CSS extensions in Mozilla. This is clearly a sign that the CSS syntax is a good language for the purposes of annotating document trees (much as XML is a good language for creating the document trees in the first place). However, the more popular the CSS syntax becomes, the more likely a property-name clash becomes. This can be solved in one of two ways: a. CSS-based languages should never be mixed, or b. Namespacing should be introduced. Of the above, (a) is not likely to be a popular choice. NAMESPACE PROPOSAL FOR CSS -------------------------- This proposal introduces a new @-rule, @namespace. The syntax is: @namespace S* [ [ URI | IDENT ] S* '{' S* ruleset* '}' | URI S* IDENT? S* ';' ] S* (Where S, URI, IDENT, and ruleset have the meanings given in CSS2, section 4.1.1). If the first form is used (the declarative form), then the following conventions apply: The URI is a unique identifier for each namespace. IDENT is a stylesheet-unique name used to refer to that namespace. If it is omitted, then the @namespace rule designates the stylesheet's default namespace. There can only be one such rule per stylesheet. @namespace rules must appear after any @charset and @import statements. If the @namespace rule includes a ruleset, then all pseudos, @rules and properties are assumed to be from that namespace (unless another namespace is explicitly given). The namespace can be designated either directly by use of a URI or indirectly by use of an INDENT declared previously. Once a namespace is defined, properties, @rules, pseudo-elements and pseudo-classes from that namespace can be referred to by prefixing them with the namespace name and a dot. For example: SELECTOR:namespace.pseudo-class { namespace.property: value; } @namespace.rule { } In the interests of backwards compatability, in the case where no default namespace is given, it is implied by the container's mime type. For example, text inside an HTML style block with type="text/css" would imply the following: @namespace uri(http://www.w3.org/TR/REC-CSS2/); EXAMPLE ------- @namespace url(http://www.w3.org/TR/REC-CSS2/); @namespace url(http://www.w3.org/TR/NOTE-AS) cas; @namespace url(http://www.w3.org/TR/WD-SVG/) svg; A { cas.onMouseOver: "window.status = this.title"; cas.onMouseOut: "window.status = ''"; text-decoration: underline; } #title { svg.fill: url(fills.svg#TitleFill); cas.onclick: "titleClick()"; } @namespace svg { #header { text-antialiasing: true; font-size: 5; font-weight: 900; } #footer { fill: url(fills.svg#Footer); } } @namespace url(http://www.mozilla.org/) { HR { border-style: -moz-rounded-corners; } } SCOPE ----- When applying the cascade, each namespace will be taken in turn, and only those that are relevant will be considered. For example, when styling an SVG document, the CSS namespace will be ignored. Similarly, when styling an XML document in an arbitrary language (e.g., not SVG, XSL, or MathML, which all have their own specific context-sensitive grammars) the SVG namespace will be ignored. In other words, SVG properties apply only to elements that are part of SVG documents. So assuming the above CSS fragment is applied to the following XHTML fragment:

This is important.

The 'fill' property will not be applied. the 'onclick' property would be applied, however, as CAS applies to most (all?) document types. OPEN ISSUES ----------- @rules, pesudeo-classes and pseudo-elements give rise to interesting situations. Currently, only CSS2 uses them; SVG and CAS do not (except that SVG uses '@font-face' by relying on CSS2 font inclusion). I think that use of a pseudo from a particular namespace probably ought to outlaw any properties from other namespaces. Or should it. I don't know. Also, the issue of how this proposal meshes with the external scripting allowed by CAS should be addressed. The grammar of CSS would have to be rewritten to take namespaces into consideration. In fact, CSS itself would have to be split into two specs; one describing the syntax, including five @rules (@charset, @import, @namespace, @font-face, @media) and one describing the CSS formatting language. REFERENCES ---------- [1] http://www.w3.org/TR/REC-CSS2/ [2] http://www.w3.org/TR/WD-SVG/ [3] http://www.w3.org/TR/NOTE-AS