JavaScript Element namespaceURI Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Element.namespaceURI is a read-only property that returns the element’s namespace URI as a string, or null if it is not in a namespace (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use el.namespaceURI. Start with this line.

JavaScript
element.namespaceURI
CallWhat it does
element.namespaceURIPrimary signature.

Built into the browser. Read or assign el.namespaceURI — no import required.

Library declarations
JavaScript
element.namespaceURI

Parameters

ParameterDescription
localNameOptional. Often checked together with the URI

Return Value

Return ValueDescription
*String or null

JavaScript Examples

Example 1 — HTML namespaceURI

Read the namespace of a normal HTML element.

JavaScript
const box = document.getElementById("box");

console.log(box.namespaceURI);
// "http://www.w3.org/1999/xhtml"
Try It Yourself

How It Works

  1. Find an HTML element. A <div> in an HTML document.
  2. Read namespaceURI. You get the XHTML namespace string.
  3. MDN note. HTML elements in HTML docs use the same URI as XHTML.
  4. Read-only. The value was set when the node was created.

Example 2 — SVG with createElementNS

Create a real SVG circle in the SVG namespace.

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

console.log(circle.namespaceURI);
// "http://www.w3.org/2000/svg"
console.log(circle.localName);
// "circle"
Try It Yourself

How It Works

  1. Pick the SVG URI. Store it in a constant for clarity.
  2. Create with createElementNS. The namespace is set at creation.
  3. Read it back. namespaceURI matches the SVG URI.
  4. localName is separate. Here it is "circle".

Example 3 — Check Namespace + Local Name

Confirm both the URI and the local name (MDN-style check).

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); // true
Try It Yourself

How It Works

  1. Same local name can exist in different namespaces. Name alone is not enough.
  2. Check localName. Here it must be "circle".
  3. Check namespaceURI. It must be the SVG URI.
  4. Both true → you have a real SVG circle element.

Browser Support

Element.namespaceURI is Baseline Widely available (MDN: since July 2015). Safe across modern and older evergreen browsers.

✓ Baseline · Widely available

Element.namespaceURI

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

99% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
namespaceURI Excellent

Bottom line: Safe for production. Use createElementNS when you need SVG or other namespaces.

Frequently Asked Questions

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.

Next: nextElementSibling

Learn how to read the next sibling Element in the DOM tree.

nextElementSibling tutorial →

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.

12 people found this page helpful