e01.org

CSS namespaces

The CSS namespaces module defines the syntax for using namespaces in CSS.

The **CSS namespaces** module defines the syntax for using namespaces in CSS.

CSS isn't just for styling HTML. A stylesheet may be used to style SVG, MathML, XML, or HTML, each of which has a different namespace or a document containing multiple namespaces.

The @namespace at-rule defined in this module enables distinguishing between same-named elements in different namespaces. Element tag names are not unique to a single language. For example, the `<a>` element isn't limited to HTML. You may want to style the `<a>`s within your SVGs differently from the links in your HTML. You also will likely want to ensure that querySelectorAll(\a\) selects the right kind of element. Namespacing can help.

The `@namespace` rule is used for declaring a default namespace and for binding namespaces to namespace prefixes. The namespaces module also defines the syntax for using these prefixes to represent namespace-qualified names. That's it. What a name means or if the name is even valid depends on the context and host language.

## Reference

### At-rules and descriptors

- @namespace

## Guides

- [Namespaces crash course](/docs/Web/SVG/Guides/Namespaces_crash_course)
- : Deep dive into what a namespace is and how they are used in XML and XML-based markup languages.

## Related concepts

- CSS [namespace separator (`|`)](/docs/Web/CSS/Reference/Selectors/Namespace_separator) combinator
- CSS [type selectors](/docs/Web/CSS/Reference/Selectors/Type_selectors)
- CSS [universal selector](/docs/Web/CSS/Reference/Selectors/Universal_selectors)
- CSSNamespaceRule interface
- CSSNamespaceRule.namespaceURI property
- CSSNamespaceRule.prefix property
- [`Document.createAttributeNS()`](/docs/Web/API/Document/createAttributeNS) method
- [`Document.createElementNS()`](/docs/Web/API/Document/createElementNS) method
- [`Document.getElementsByTagNameNS()`](/docs/Web/API/Document/getElementsByTagNameNS) method
- [`Element.getAttributeNodeNS()`](/docs/Web/API/Element/getAttributeNodeNS) method
- [`Element.getAttributeNS()`](/docs/Web/API/Element/getAttributeNS) method
- [`Element.getElementsByTagNameNS()`](/docs/Web/API/Element/getElementsByTagNameNS) method
- [`Element.hasAttributeNS()`](/docs/Web/API/Element/hasAttributeNS) method
- [`Element.namespaceURI`](/docs/Web/API/Element/namespaceURI) property
- [`Element.removeAttributeNS()`](/docs/Web/API/Element/removeAttributeNS) method
- [`Element.setAttributeNS()`](/docs/Web/API/Element/setAttributeNS) method
- [`Element.setAttributeNodeNS()`](/docs/Web/API/Element/setAttributeNodeNS) method
- [`NamedNodeMap.getNamedItemNS()`](/docs/Web/API/NamedNodeMap/getNamedItemNS) method
- [`NamedNodeMap.removeNamedItemNS()`](/docs/Web/API/NamedNodeMap/removeNamedItemNS) method
- [`NamedNodeMap.setNamedItemNS()`](/docs/Web/API/NamedNodeMap/setNamedItemNS) method
- Namespace glossary term

## Specifications

## See also

- [`<a>`](/docs/Web/SVG/Reference/Element/a#example) SVG element
- &lt;url&gt; data type
- [CSS at-rules](/docs/Web/CSS/Guides/Syntax/At-rules)
- [CSS at-rule functions](/docs/Web/CSS/Reference/At-rules/At-rule_functions)
- [CSS selectors](/docs/Web/CSS/Guides/Selectors)

source: MDN Web Docs mirror · page

Cite this

"CSS namespaces". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Namespaces

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·