document.createElementNS(namespaceURI, qualifiedName) creates a new Element with an explicit namespace. Use it for SVG, MathML, or other mixed-namespace documents where createElement() is not enough.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.createElementNS. Start with this line.
JavaScript
document.createElementNS(ns, name)
Call
What it does
document.createElementNS(ns, name)
Primary signature.
document.createElementNS(...)
Call with the arguments your case needs.
Built into the browser. Call createElementNS(...) on document — no import required.
Library declarations
JavaScript
document.createElementNS(ns, name)
Parameters
Parameter
Description
namespaceURI
Required. Namespace string (or null in some cases)
qualifiedName
Required. Tag name, optionally prefix:localName
options
Optional. Custom element is / registry (advanced)
Return Value
Return Value
Description
*
The value returned by document.createElementNS().
JavaScript Examples
Example 1 — Create an SVG Circle
Build a small SVG root and a circle in the SVG namespace, then append them.
Use the XHTML URI. That is the HTML namespace in the DOM.
Create with createElementNS. You get a normal HTMLDivElement.
Create with createElement. Same namespace and interface for plain HTML.
Prefer the simple API. For everyday HTML tags, stick with createElement().
Compatibility
Browser Support
Document.createElementNS() is a long-standing DOM API. MDN lists it as Baseline Widely available across modern browsers.
✓ Baseline · DOM
Document.createElementNS()
Supported in Chrome, Firefox, Safari, Edge, and other evergreen browsers. Safe for SVG and MathML creation in everyday web apps.
99%Universal API
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
createElementNS()Excellent
Bottom line: Safe everywhere you build SVG from script. Remember: HTML tags → createElement; SVG/MathML → createElementNS. See also the MDN createElementNS() reference.
Frequently Asked Questions
It creates a new Element with a given namespace URI and qualified name. Use it for SVG, MathML, or other namespaces in mixed documents.
No. MDN marks Document.createElementNS() as Baseline Widely available. It is not Deprecated, Experimental, or Non-standard.
Prefer createElement() for plain HTML tags. Use createElementNS() when you need an explicit namespace — especially SVG or MathML inside HTML.
In an HTML document, createElement("svg") returns an HTMLUnknownElement, so the SVG will not render correctly. Use createElementNS with http://www.w3.org/2000/svg.