Build a tiny XML string with a prefixed element and xmlns:x.
Parse as application/xml. That uses a namespace-aware parser.
Read documentElement.prefix. You get "x" (MDN’s idea).
localName is "div" — the part after the colon.
Compatibility
Browser Support
Element.prefix is Baseline Widely available (MDN: since July 2015). The property exists everywhere; non-null values depend on namespace-aware creation/parsing.
✓ Baseline · Widely available
Element.prefix
Read-only namespace prefix string or null — useful mainly with XML / createElementNS.
99%Widely available
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
prefixExcellent
Bottom line: Safe API. For real prefixes, use XML parsing or a prefixed createElementNS name.
Frequently Asked Questions
The namespace prefix of the element as a string, or null if no prefix is specified.
No. MDN marks Element.prefix as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Normal HTML parsing is not namespace-aware in the XML sense. MDN notes prefix is meaningful when a namespace-aware parser is used (XML MIME type / application/xml).
prefix is the short alias (for example x). localName is the name after the colon. namespaceURI is the full namespace address.
No. It is read-only. Create the element with the desired qualified name via createElementNS or parse XML.
Parse XML with DOMParser and application/xml, or createElementNS with a prefixed qualified name such as "x:box".