JavaScript Element namespaceURI 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.
| Call | What it does |
|---|
element.namespaceURI | Primary signature. |
Built into the browser. Read or assign el.namespaceURI — no import required.
Library declarations
Parameters
| Parameter | Description |
|---|
| localName | Optional. Often checked together with the URI |
Return Value
| Return Value | Description |
|---|
| * | String or null |
JavaScript Examples
Example 1 — HTML namespaceURI
Read the namespace of a normal HTML element.
const box = document.getElementById("box");
console.log(box.namespaceURI);
// "http://www.w3.org/1999/xhtml"
http://www.w3.org/1999/xhtml
How It Works
- Find an HTML element. A
<div> in an HTML document. - Read
namespaceURI. You get the XHTML namespace string. - MDN note. HTML elements in HTML docs use the same URI as XHTML.
- 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.
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"
http://www.w3.org/2000/svg
circle
How It Works
- Pick the SVG URI. Store it in a constant for clarity.
- Create with
createElementNS. The namespace is set at creation. - Read it back.
namespaceURI matches the SVG URI. localName is separate. Here it is "circle".
Example 3 — Check Namespace + Local Name
Confirm both the URI and the local name (MDN-style check).
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
How It Works
- Same local name can exist in different namespaces. Name alone is not enough.
- Check
localName. Here it must be "circle". - Check
namespaceURI. It must be the SVG URI. - Both true → you have a real SVG circle element.
Compatibility
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.
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 supportnamespaceURI 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.
About the author
Developer, cloud engineer, and technical writer
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