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
Fundamentals
Introduction
Namespaces keep element names from colliding across vocabularies. HTML, SVG, and MathML can all use short names like a or title—namespaceURI 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().
Think of localName as the short tag name and namespaceURI as the “family” that name belongs to.
Concept
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).
Foundation
📝 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.
Item
Detail
Type
string or null
Access
Read-only property
HTML elements
http://www.w3.org/1999/xhtml
Create with URI
document.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.
Pattern
📋 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().
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.
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported
Yes
namespaceURIBaseline
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.
Wrap Up
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.