The Node.lookupNamespaceURI() method turns a prefix into a namespace URI on a node. Learn default-namespace lookups with null, the special xml / xmlns prefixes, and how this pairs with isDefaultNamespace().
01
Kind
Instance method
02
Returns
string | null
03
Arg
Prefix (or null)
04
Default
null / "" prefix
05
Specials
xml & xmlns
06
Status
Baseline widely
Fundamentals
Introduction
In XML-style markup, a prefix (like xlink: or svg:) is a short label bound to a long namespace URI. The browser (and XPath) need that URI to know which vocabulary a name belongs to.
lookupNamespaceURI(prefix) asks a node: “What URI is bound to this prefix here?” Pass null (or "") to read the default namespace—the one for unprefixed names.
💡
Beginner tip
Everyday HTML pages rarely need this. It shines for SVG, MathML, XML, and XPath namespace resolvers. Prefer createElementNS in demos so results stay clear.
Concept
Understanding lookupNamespaceURI()
MDN: given a prefix, return the associated namespace URI on that node, or null if none is found. Nodes can also be passed as namespace resolvers to XPath createExpression / evaluate.
Found — returns the URI string for that prefix.
Not found — returns null.
Default — null or "" means the default namespace.
Built-ins — "xml" and "xmlns" always map to fixed URIs.
Foundation
📝 Syntax
JavaScript
const uri = node.lookupNamespaceURI(prefix);
Parameters
prefix — The prefix to look up. Empty string is equivalent to null (default namespace). Required in the signature, but may be null.
Return value
A string containing the namespace URI for that prefix, or null if there is none.
Rules
📋 Return Value Rules (MDN)
Situation
Result
prefix is null or ""
Default namespace URI (or null)
prefix is "xml"
Always http://www.w3.org/XML/1998/namespace
prefix is "xmlns"
Always http://www.w3.org/2000/xmlns/
Prefix not found
null
DocumentFragment, DocumentType, Document without documentElement, or Attr without an element
Always null
Reference
🌐 Common Namespace URIs
Vocabulary
Namespace URI
HTML (XHTML)
http://www.w3.org/1999/xhtml
SVG
http://www.w3.org/2000/svg
MathML
http://www.w3.org/1998/Math/MathML
XLink
http://www.w3.org/1999/xlink
XML (built-in xml)
http://www.w3.org/XML/1998/namespace
xmlns (built-in xmlns)
http://www.w3.org/2000/xmlns/
Caveat
⚠️ HTML Documents vs Namespaces
MDN’s example note: in an HTML document, most xmlns: attributes are ignored (except xmlns:xlink). Firefox may report null for element namespaces, while Chrome and Safari often set HTML, SVG, and MathML defaults.
For learning and reliable tests, create nodes with createElementNS, or run scripts in a standalone SVG document as MDN suggests.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Default namespace URI
node.lookupNamespaceURI(null)
Same with empty string
node.lookupNamespaceURI("")
Look up a prefix
node.lookupNamespaceURI("xlink")
Built-in xml URI
node.lookupNamespaceURI("xml")
Default check via isDefaultNamespace
node.isDefaultNamespace(uri)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about Node.lookupNamespaceURI().
Returns
string|null
URI or null
Baseline
widely
Since July 2015
Default
null / ""
Same meaning
Specials
xml, xmlns
Fixed URIs
Hands-On
Examples Gallery
Examples follow MDN Node.lookupNamespaceURI() ideas, using createElementNS for clearer results. Use View Output or Try It Yourself.
📚 Getting Started
Default namespace and the built-in prefixes.
Example 1 — Default Namespace with null and ""
Create an SVG node, then read its default namespace two ways.
JavaScript
const SVG_NS = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(SVG_NS, "svg");
console.log(svg.lookupNamespaceURI(null)); // SVG_NS
console.log(svg.lookupNamespaceURI("")); // same as null
console.log(svg.namespaceURI); // SVG_NS
Node.lookupNamespaceURI() is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Results inside HTML documents can still differ for namespaces—test with createElementNS when teaching.
✓ Baseline · Widely available
Node.lookupNamespaceURI()
Safe API; watch HTML-document quirks. Use SVG/MathML createElementNS for clear demos.
UniversalWidely available
Google ChromeFull support · Sets HTML/SVG/MathML defaults
Full support
Mozilla FirefoxFull API; HTML default NS often null (MDN)
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerLong-standing support in legacy IE
Full support
lookupNamespaceURI()Excellent
Bottom line: Prefix → URI lookup; null/"" means default namespace; xml/xmlns are fixed.
Wrap Up
Conclusion
Node.lookupNamespaceURI() resolves a prefix to a namespace URI—or null when unbound. Pass null / "" for the default, remember the fixed xml / xmlns mappings, and pair it with isDefaultNamespace when you only need a boolean check.
Confuse default namespace with a declared prefix of the same name
Forget some node types always return null
Confuse DOM Node with the Node.js runtime
Skip browser checks when teaching HTML-document quirks
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about lookupNamespaceURI()
Prefix in, namespace URI (or null) out.
5
Core concepts
🌐01
Prefix → URI
or null
API
∅02
null / ""
default NS
Default
🔒03
xml & xmlns
fixed URIs
Special
⚖️04
Pairs with
isDefaultNS
Related
⚠️05
HTML quirks
use createNS
Caveat
❓ Frequently Asked Questions
It takes a namespace prefix and returns the matching namespace URI on that node, or null if none is found. Passing null (or an empty string) looks up the default namespace.
No. MDN marks Node.lookupNamespaceURI() as Baseline Widely available (since July 2015). It is a standard DOM method — not Deprecated, Experimental, or Non-standard.
isDefaultNamespace(uri) is equivalent to node.lookupNamespaceURI(null) === uri. Use lookupNamespaceURI(null) when you need the default URI string itself.
MDN: always null for a DocumentFragment, DocumentType, Document with no documentElement, or Attr with no associated element. Unknown prefixes also return null.
It resolves prefixes for XML/SVG tooling and can act as a namespace resolver for XPathEvaluator.createExpression() and evaluate(). Everyday HTML UI rarely needs it.
Did you know?
MDN highlights that lookupNamespaceURI exists so Node objects can serve as namespace resolvers for XPath—not only for one-off debugging. The same method you use in a tutorial can power expression evaluation against prefixed names.