JavaScript Node lookupNamespaceURI() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Instance method

What You’ll Learn

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

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.

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.
  • Defaultnull or "" means the default namespace.
  • Built-ins"xml" and "xmlns" always map to fixed URIs.

📝 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.

📋 Return Value Rules (MDN)

SituationResult
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 foundnull
DocumentFragment, DocumentType, Document without documentElement, or Attr without an elementAlways null

🌐 Common Namespace URIs

VocabularyNamespace URI
HTML (XHTML)http://www.w3.org/1999/xhtml
SVGhttp://www.w3.org/2000/svg
MathMLhttp://www.w3.org/1998/Math/MathML
XLinkhttp://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/

⚠️ 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.

⚡ Quick Reference

GoalCode
Default namespace URInode.lookupNamespaceURI(null)
Same with empty stringnode.lookupNamespaceURI("")
Look up a prefixnode.lookupNamespaceURI("xlink")
Built-in xml URInode.lookupNamespaceURI("xml")
Default check via isDefaultNamespacenode.isDefaultNamespace(uri)
MDN statusBaseline Widely available (since July 2015)

🔍 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

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
Try It Yourself

How It Works

MDN treats empty string like null: both mean “default namespace.” For an SVG element created with createElementNS, that URI is the SVG namespace.

Example 2 — Built-in xml and xmlns Prefixes

These prefixes always resolve to fixed URIs, on any normal element node.

JavaScript
const el = document.createElement("div");

console.log(el.lookupNamespaceURI("xml"));
// http://www.w3.org/XML/1998/namespace

console.log(el.lookupNamespaceURI("xmlns"));
// http://www.w3.org/2000/xmlns/
Try It Yourself

How It Works

You do not declare these bindings yourself. The DOM always maps "xml" and "xmlns" to the standard URIs.

📈 Prefixes, Misses & Equivalence

XLink lookups, unknown prefixes, and isDefaultNamespace.

Example 4 — Unknown Prefix Returns null

If the prefix is not bound on the node, the result is null.

JavaScript
const SVG_NS = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(SVG_NS, "svg");

console.log(svg.lookupNamespaceURI("svg"));   // null (no "svg" prefix declared)
console.log(svg.lookupNamespaceURI("nope"));  // null
console.log(String(svg.lookupNamespaceURI("nope")));
Try It Yourself

How It Works

Being in the SVG namespace (default) is not the same as declaring a svg: prefix. Unbound prefixes resolve to null.

Example 5 — Same Idea as isDefaultNamespace()

MDN: isDefaultNamespace(uri)lookupNamespaceURI(null) === uri.

JavaScript
const SVG_NS = "http://www.w3.org/2000/svg";
const HTML_NS = "http://www.w3.org/1999/xhtml";
const svg = document.createElementNS(SVG_NS, "circle");

const defaultUri = svg.lookupNamespaceURI(null);
console.log(defaultUri);                         // SVG_NS
console.log(svg.isDefaultNamespace(SVG_NS));     // true
console.log(defaultUri === SVG_NS);              // true
console.log(svg.isDefaultNamespace(HTML_NS));    // false
Try It Yourself

How It Works

Use lookupNamespaceURI(null) when you need the URI string. Use isDefaultNamespace when you only need a yes/no check against a known URI.

🚀 Common Use Cases

  • Reading a node’s default namespace URI for SVG, MathML, or XML tooling.
  • Resolving prefixes such as xlink before reading namespaced attributes.
  • Acting as a namespace resolver for XPath createExpression / evaluate.
  • Teaching how default namespaces relate to isDefaultNamespace().
  • Debugging mixed documents when prefixes and defaults confuse markup.

🔧 How It Works

1

Pass a prefix

String prefix, null, or empty string (default namespace).

Arg
2

Apply specials

xml and xmlns map to fixed URIs; some node types always null.

Rules
3

Search bindings

Find the URI bound to that prefix in the node’s context.

Resolve
4

URI or null

Use the string in tooling, or null when unbound.

📝 Notes

Universal Browser Support

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.

Universal Widely available
Google Chrome Full support · Sets HTML/SVG/MathML defaults
Full support
Mozilla Firefox Full API; HTML default NS often null (MDN)
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Long-standing support in legacy IE
Full support
lookupNamespaceURI() Excellent

Bottom line: Prefix → URI lookup; null/"" means default namespace; xml/xmlns are fixed.

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.

Continue with lookupPrefix(), isDefaultNamespace(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use createElementNS in teaching demos
  • Treat null and "" as default-namespace lookups
  • Remember fixed xml / xmlns URIs
  • Use isDefaultNamespace for yes/no URI checks
  • Expect null for unbound prefixes

❌ Don’t

  • Assume HTML xmlns: attributes always apply
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about lookupNamespaceURI()

Prefix in, namespace URI (or null) out.

5
Core concepts
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.
MDN: prefix "xml" always returns "http://www.w3.org/XML/1998/namespace". Prefix "xmlns" always returns "http://www.w3.org/2000/xmlns/".
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.

Next: lookupPrefix()

Learn how to resolve a namespace URI to a prefix.

lookupPrefix() →

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.

5 people found this page helpful