5. Specifying namespaces
Prev | Chapter 4. Other extensions | Next

## 5. Specifying namespaces

Namespace support in CSS3 style sheets is outlined in Selectors. In summary:

- `@namespace` rule declares a namespace prefix and associates it to the namespace URI. Examples:

      @namespace url(http://www.xmlmind.com/xmleditor/schema/configuration);

      @namespace html url(http://www.w3.org/1999/xhtml);

  Rule #1 specifies that element names (in selectors) without an explicit namespace component belong to the "`http://www.xmlmind.com/xmleditor/schema/configuration`" namespace.

  Rule #2 specifies that element or attribute names with a "`html`" prefix belong to the "`http://www.w3.org/1999/xhtml`" namespace.

- Notation for qualified names is `prefix``|``local_name`, where character `'|'` is used to separate the two parts of the qualified name.

  Example of element names:

      @namespace ns url(http://www.ns.com);

      ns|para { font-size: 8pt;  }
      ns|*    { font-size: 9pt;  }
      |para   { font-size: 10pt; }
      *|para  { font-size: 11pt; }
      para    { font-size: 11pt; }

  Rule #1

    will match only `para` elements in the "`http://www.ns.com`" namespace.

  Rule #2

    will match all elements in the "`http://www.ns.com`" namespace.

  Rule #3

    will match only `para` elements without any declared namespace.

  Rule #4

    will match `para` elements in any namespace (including those without any declared namespace).

  Rule #5

    is equivalent to the rule #4 because no default namespace has been defined.

  Examples of attribute names:

      @namespace ns "http://www.ns.com";

      [ns|role=minor] { font-size: 8pt; }
      [*|role]        { font-size: 9pt; }
      [|role]         { font-size: 10pt; }
      [role]          { font-size: 10pt; }

  Rule #1

    will match only elements with the attribute `role` in the "`http://www.ns.com`" namespace with the value "`minor`".

  Rule #2

    will match only elements with the attribute `role` regardless of the namespace of the attribute (including no declared namespace).

  Rule #3 and #4

    will match only elements with the attribute `role` where the attribute is not declared to be in a namespace.

    Note that default namespaces do not apply to attributes.

- The `attr()` pseudo-function also supports namespaces.

      @namespace ns "http://www.ns.com";

      para:before { content: attr(ns|role); }

  The generated content inserted before "`para`" elements is the content of attribute `role` declared in the "`http://www.ns.com`" namespace.

Prev | Up | Next
4. Styling an element which contains a specific child element | Home | 6. Inserting in generated content the name of the element which is the target of the CSS rule