CSS At-Rule
Description
The @namespace at-rule provides a way for a stylesheet to bind a short prefix to a namespace identifier so that selectors can target elements and attributes that belong to particular XML namespaces. It exists to bridge CSS selector syntax with XML namespacing concepts: by declaring these bindings, authors can write selectors that explicitly refer to elements in different namespaces, disambiguating identically named elements that come from different vocabularies (for example, SVG versus XHTML).
Rather than changing or assigning namespaces on document nodes, the at-rule purely affects how the stylesheet resolves names in selectors. When a selector uses a namespace prefix, the stylesheet uses the mapping established by the @namespace declarations to determine which elements match. Default-namespace declarations (when provided) change how unprefixed element names in selectors are interpreted, but none of these declarations alters the DOM or the underlying namespace information of the document itself — they only change the name-resolution context that CSS uses for matching.
Namespace declarations in a stylesheet are global to the stylesheet’s rule-processing: they establish name bindings used for subsequent selector resolution and can be redefined within the same stylesheet, with later declarations taking precedence for that prefix. This behavior is about name resolution rather than the cascade of style properties, so conflicts or redefinitions of prefixes do not follow the same rules as conflicting style declarations; they simply change how subsequent selectors are interpreted.
Practically, @namespace is most useful when styling XML-based content or embedded XML vocabularies (for example, SVG or MathML) where elements share local names across different namespaces. Best practice is to keep namespace declarations clear and near the top of a stylesheet, use concise, meaningful prefixes, and avoid introducing unnecessary namespace bindings in plain HTML contexts unless you need to target embedded namespaced content — doing so improves readability and prevents subtle selector mismatches.
Syntax
namespace <namespace-prefix>? [ <string> | <url> ]; where <namespace-prefix> = <ident>
Values
- none
Example
Browser Support
The following information will show you the current browser support for the CSS at-rule @namespace. Hover over a browser icon to see the version that first introduced support for this CSS at-rule.
This at-rule is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 28th December 2025
