CSS @namespace At-Rule

Beginner
3 examples
Updated: Nov 2026

Definition and Usage

The @namespace at-rule declares an XML namespace for CSS type selectors. Use it when styling SVG or other namespaced markup so svg|a matches only namespaced elements.

CSS Syntax

syntax.css
@namespace url("http://www.w3.org/2000/svg");
@namespace svg url("http://www.w3.org/2000/svg");

Key Parts

PartPurposeTry it
defaultApply a default namespace to bare type selectorsTry it
prefixBind a short prefix such as svg|circleTry it
url()Point at the namespace URI stringTry it

CSS Examples

Default SVG namespace

example.css
@namespace url("http://www.w3.org/2000/svg");
circle { fill: teal; }
Try It Yourself

Prefixed selectors

example.css
@namespace svg url("http://www.w3.org/2000/svg");
svg|rect { stroke: navy; }
Try It Yourself

Browser Support

@namespace is a modern CSS at-rule.

✓ Modern CSS

@namespace

Check current browsers before relying on advanced behavior.

90% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
@namespace Modern support

Bottom line: Use progressive enhancement. Keep a readable fallback when a browser ignores the at-rule.

Frequently Asked Questions

When type selectors must distinguish HTML from SVG or other XML namespaces.
No. It mainly affects type element selectors and universal selectors with a namespace.
After @charset and @import, before other rules.
Rare for plain HTML pages. It matters more for SVG/XML documents.
All modern browsers support CSS namespaces.

Next: @page

Continue with @page.

@page tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful