大网数据广告活动
Web 标准与前端开发

CSS namespaces

· 52CE 我爱测

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

The CSS namespaces module defines the syntax for using namespace 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 Document.querySelectorAll 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
    • : Deep dive into what a namespace is and how they are used in XML and XML-based markup languages.

Related concepts

Specifications

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。