JavaScript Element namespaceURI Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance property

What You’ll Learn

Element.namespaceURI is a read-only instance property that returns the element’s namespace URI as a string, or null when there is no namespace. Learn the HTML and SVG URIs, how createElementNS sets it, and how to pair it with localName—with five examples and try-it labs.

01

Kind

Instance property

02

Access

Read-only

03

Type

string or null

04

HTML URI

XHTML namespace

05

Status

Baseline widely

06

Pairs with

localName

Introduction

Namespaces keep element names from colliding across vocabularies. HTML, SVG, and MathML can all use short names like a or titlenamespaceURI tells you which vocabulary an element belongs to.

In a normal HTML page, almost every HTML tag reports the XHTML namespace URI. SVG elements report the SVG namespace. You create namespaced nodes with document.createElementNS().

JavaScript
const box = document.getElementById("box");
console.log(box.namespaceURI);
// "http://www.w3.org/1999/xhtml"
💡
Beginner tip

Think of localName as the short tag name and namespaceURI as the “family” that name belongs to.

Understanding the Property

MDN: the read-only namespaceURI property returns the namespace URI of the element, or null if the element is not in a namespace.

  • Read-only — fixed when the node is created.
  • String or null — a URI string, or no namespace.
  • HTML default — HTML elements use http://www.w3.org/1999/xhtml.
  • Baseline — widely available since July 2015 (MDN).

📝 Syntax

JavaScript
namespaceURI

Value

A string containing the namespace URI, or null when the element has no namespace. The value is frozen at creation—it is not recomputed from later xmlns lookups.

ItemDetail
Typestring or null
AccessRead-only property
HTML elementshttp://www.w3.org/1999/xhtml
Create with URIdocument.createElementNS(uri, name)
⚠️
Frozen at creation

MDN: this is not a live lookup from in-scope namespace declarations. Changing xmlns later does not rewrite an existing node’s namespaceURI.

📋 MDN Check Example Shape

MDN pairs localName and namespaceURI to identify a specific element type (XUL example shown conceptually):

JavaScript
if (
  element.localName === "browser" &&
  element.namespaceURI ===
    "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
) {
  // this is a XUL browser
}

In everyday web pages, the same idea applies to SVG: localName === "circle" and namespaceURI === "http://www.w3.org/2000/svg".

Related learning: localName, prefix, and createElementNS().

⚡ Quick Reference

GoalCode / note
Read namespaceel.namespaceURI
HTML checkel.namespaceURI === "http://www.w3.org/1999/xhtml"
SVG checkel.namespaceURI === "http://www.w3.org/2000/svg"
Create SVG nodedocument.createElementNS(SVG_NS, "circle")
Pair with nameel.localName + el.namespaceURI
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.namespaceURI.

Kind
get only

Instance

Type
string|null

URI or none

HTML
xhtml NS

Default URI

Baseline
widely

Jul 2015+

Examples Gallery

Examples follow MDN Element: namespaceURI. Labs use HTML and SVG nodes so you can compare namespaces in the browser.

📚 Getting Started

Read the namespace of a normal HTML element.

Example 1 — HTML Element Namespace

HTML elements in HTML documents use the XHTML namespace URI.

JavaScript
const box = document.getElementById("box");
console.log(box.namespaceURI);
Try It Yourself

How It Works

Even though the markup looks like plain HTML, the DOM assigns the XHTML namespace URI to HTML elements in HTML documents (MDN).

📈 SVG, Pairing & Creation

Compare SVG namespaces, check both properties, and create namespaced nodes.

Example 2 — SVG Namespace

SVG elements report the SVG namespace URI.

JavaScript
const circle = document.createElementNS(
  "http://www.w3.org/2000/svg",
  "circle"
);
console.log(circle.namespaceURI);
console.log(circle.localName);
Try It Yourself

How It Works

createElementNS stamps the namespace onto the node at creation. That URI is what namespaceURI returns later.

Example 3 — Pair with localName

Identify an SVG circle the same way MDN pairs name + namespace.

JavaScript
const SVG_NS = "http://www.w3.org/2000/svg";
const el = document.createElementNS(SVG_NS, "circle");
const isSvgCircle =
  el.localName === "circle" && el.namespaceURI === SVG_NS;
console.log(isSvgCircle);
Try It Yourself

How It Works

Checking only localName can be ambiguous across vocabularies. Adding namespaceURI makes the identity check precise.

Example 4 — createElement vs createElementNS

Same local name, different namespaces.

JavaScript
const htmlA = document.createElement("a");
const svgA = document.createElementNS(
  "http://www.w3.org/2000/svg",
  "a"
);
console.log(htmlA.namespaceURI);
console.log(svgA.namespaceURI);
console.log(htmlA.localName === svgA.localName);
Try It Yourself

How It Works

Both elements can be named a, but they live in different namespaces—so they are different kinds of nodes.

Example 5 — Support Snapshot

Feature-detect and remember the HTML/SVG URI constants.

JavaScript
console.log({
  supported: "namespaceURI" in Element.prototype,
  returns: "string or null",
  htmlNS: "http://www.w3.org/1999/xhtml",
  svgNS: "http://www.w3.org/2000/svg",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Safe to use broadly. Store common namespace URIs in constants when you work with SVG or mixed markup often.

🚀 Common Use Cases

  • Confirming an HTML element uses the XHTML namespace.
  • Detecting SVG nodes before using SVG-specific APIs.
  • Pairing with localName for precise element identity checks.
  • Debugging mixed HTML/SVG documents and unexpected createElement results.
  • Validating nodes created with createElementNS.

🔧 How It Works

1

Node is created

Via parser, createElement, or createElementNS.

Create
2

Namespace is stamped

Frozen on the node at creation time (MDN).

Freeze
3

Reading returns URI or null

HTML tags usually report the XHTML URI.

Read
4

Pair with localName

Name + namespace uniquely identify the element kind.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available).
  • Read-only and frozen at creation—not a live xmlns lookup.
  • The DOM does not enforce namespace validation for you; apps decide what is valid.
  • Related: localName, prefix, createElementNS(), nextElementSibling, JavaScript hub.

Browser Support

Element.namespaceURI is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.namespaceURI

Read-only — returns the element's namespace URI string, or null if none.

Baseline Widely available
Google Chrome Supported
Yes
Microsoft Edge Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Opera Supported
Yes
Internet Explorer Supported
Yes
namespaceURI Baseline

Bottom line: Use namespaceURI to see which vocabulary an element belongs to. HTML uses the XHTML URI; SVG uses the SVG URI. Pair it with localName for precise checks.

Conclusion

namespaceURI tells you which namespace an element belongs to. In HTML pages that is usually the XHTML URI; for SVG it is the SVG URI. Combine it with localName when you need a precise identity check.

Continue with nextElementSibling, localName, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Store common URIs in constants (SVG_NS, HTML_NS)
  • Use createElementNS for SVG/MathML nodes
  • Check localName and namespaceURI together
  • Remember the value is frozen at creation
  • Expect XHTML URI on HTML elements in HTML documents

❌ Don’t

  • Assign to namespaceURI (read-only)
  • Assume changing xmlns later updates existing nodes
  • Create SVG with plain createElement("circle") and expect SVG behavior
  • Ignore namespaces when local names collide across vocabularies
  • Treat the DOM as a full namespace validator

Key Takeaways

Knowledge Unlocked

Five things to remember about namespaceURI

Read-only URI string or null—frozen at creation.

5
Core concepts
📝 02

string|null

URI or none

Type
🔍 03

HTML/SVG

known URIs

Use
04

Baseline

widely available

Status
🎯 05

Pair name

with localName

Tip

❓ Frequently Asked Questions

It returns the namespace URI of the element as a string, or null if the element is not in a namespace.
No. MDN marks Element.namespaceURI as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
In HTML documents, HTML elements use http://www.w3.org/1999/xhtml (the same namespace as XHTML).
Use document.createElementNS(namespaceURI, qualifiedName). For SVG, use http://www.w3.org/2000/svg.
No. MDN notes the namespace URI is frozen at node creation time — it is not recomputed from later namespace declarations.
localName is the local tag name (for example circle). namespaceURI is which namespace that name belongs to. You often check both together.
Did you know?

HTML elements in HTML documents share the XHTML namespace URI (http://www.w3.org/1999/xhtml) even when your source file is written as classic HTML.

Next: nextElementSibling

Learn how Element.nextElementSibling reads the following sibling element.

nextElementSibling →

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