@namespace
Example
a { color: blue; }
@namespace svg url(http://www.w3.org/2000/svg);
svg|a { fill: blue; }@namespace svg url(http://www.w3.org/2000/svg);
a { color: blue; }
svg|a { fill: blue; }@namespace must come before style rules, otherwise it is ignored and svg|a never matches.
Common mistakes
- Adding
@namespaceto plain HTML pages where it has no practical effect. - Placing
@namespaceafter other style rules, so the browser ignores it.
Key points
@namespacerules come after@charsetand@importand before all other rules.- Prefixed selectors use the
prefix|elementsyntax, likesvg|a, with a declared prefix.
Interview questions
Do I need @namespace for inline SVG in HTML?
Usually no. Type selectors like svg and circle already match inline SVG elements in HTML documents.
What does the | character mean in a CSS selector?
It separates a namespace prefix from an element or attribute name, as in svg|a or *|a for any namespace.