node.lookupNamespaceURI(prefix) returns the namespace URI for that prefix on the node, or null if none is found (MDN).
Status: Baseline Widely available (since July 2015) — not Deprecated, Experimental, or Non-standard. In HTML pages, namespace results can differ by browser — prefer createElementNS for clear demos.
Remember
node.lookupNamespaceURI(prefix)
→ URI string | null
null or "" → default namespace URI
"xml" → http://www.w3.org/XML/1998/namespace
"xmlns" → http://www.w3.org/2000/xmlns/
unknown → null
isDefaultNamespace(uri) ≡
lookupNamespaceURI(null) === uri
Pass a prefix (or null for the default) and read the URI string.
Get a node (often created with createElementNS).
Choose a prefix — or null / "" for the default.
Call node.lookupNamespaceURI(prefix).
Handle null when the prefix is missing or the node type never resolves.
Piece
Required?
Role
node
Yes
Node to inspect
prefix
Yes (may be null)
Prefix to resolve; null/"" = default
Return
—
Namespace URI string, or null
Pseudocode
Pseudocode
if prefix is "xml":
return "http://www.w3.org/XML/1998/namespace"
if prefix is "xmlns":
return "http://www.w3.org/2000/xmlns/"
if prefix is null or "":
return default namespace URI (or null)
if prefix is bound on this node (or ancestors):
return that URI
else:
return null
Compare with ===. Same question as isDefaultNamespace.
Both should match. Useful when debugging mismatches.
Pick the API. Use this method when you need the URI string itself.
Edge Cases & Pitfalls
Check these before relying on prefix lookups in HTML pages.
html
HTML documents vary by browser
MDN: xmlns: is mostly ignored in HTML (except xmlns:xlink). Firefox may report null; Chrome/Safari often set HTML/SVG/MathML defaults. Prefer createElementNS or an SVG document.
null
Some node types always return null
MDN: DocumentFragment, DocumentType, Document with no documentElement, or Attr with no associated element.
create
createElement("svg") is not enough
Use createElementNS so the element actually has the SVG namespace.
Node.lookupNamespaceURI() is marked Baseline Widely available on MDN (since July 2015).
✓ Baseline · Widely available
Node.lookupNamespaceURI()
Resolves a namespace prefix to a URI (null/"" = default). Fixed URIs for xml and xmlns. Useful as an XPath namespace resolver. Not Deprecated, Experimental, or Non-standard.
Fine for occasional XML/SVG checks. Cache the result if you resolve the same prefix in a loop. Everyday HTML UI rarely needs this API.
Remember
Key Takeaways
Prefix → URI: returns a string or null.
Default: pass null or "".
xml / xmlns: fixed URIs every time.
Pair APIs:isDefaultNamespace for yes/no; lookupPrefix for the reverse.
One line:lookupNamespaceURI turns a prefix (or null for default) into a namespace URI — or null.
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.