interface
Cssnamespacerule — CSS reference
Represents a namespace declaration used to qualify selectors. The prefix and namespace URI identify the mapping; this is distinct from changing an element namespace. This creates a separate stylesheet because namespace declarations must precede ordinary style rules.
Formal Syntax & Structure
css syntaxcss
rule.prefix; rule.namespaceURIWorking Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSSNamespaceRule</title><style>body{margin:8px;font:16px/20px sans-serif;color:black;background:white}#a{color:green}</style><body><p id="a">Sample text</p><p>Run once, then reload the page to repeat from the original state.</p><button id="run" type="button">Run example</button><pre id="result" aria-live="polite"></pre><script>const target=document.getElementById('a');const sheet=document.styleSheets[0];async function demo(){const s=document.createElement("style");s.textContent="@namespace svg url(http://www.w3.org/2000/svg);";document.head.append(s);const r=s.sheet.cssRules[0];return [r instanceof CSSNamespaceRule,r.prefix,r.namespaceURI];}document.getElementById('run').onclick=async()=>{try{document.getElementById('result').textContent=JSON.stringify(await demo());}catch(e){document.getElementById('result').textContent=e.name+': '+e.message;}};</script></body></html>