Document.xmlVersion is a deprecated read-only instance property that reported the version from the XML declaration. Learn why it almost always returned "1.0", how it pairs with xmlEncoding, MDN’s HTML-vs-XML detection trick, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
string
03
Default
"1.0"
04
Useful?
Rarely
05
Replace
createElement
06
Status
Deprecated
Fundamentals
Introduction
XML documents can begin with a declaration such as <?xml version="1.0"?>. The version attribute tells parsers which XML specification rules apply.
MDN: Document.xmlVersion returned that version number, or "1.0" when the declaration was absent. MDN also warns the property was never really useful—it almost always returned "1.0"—and it was removed from DOM Level 4. Firefox 10 no longer implements it.
💡
Old use case: HTML vs XML mode
In the past, some scripts read xmlVersion to guess whether the document was XML. MDN recommends a different test: create a lowercase element and check if the tag name becomes uppercase (HTML mode uppercases unknown tags).
See also the xmlEncoding tutorial. Avoid both in new code.
Example 4 — MDN: Detect Non-XML HTML Mode
MDN’s recommended replacement for the old xmlVersion use case.
JavaScript
if (document.createElement("foo").tagName === "FOO") {
console.log("Document is in non-XML HTML mode");
} else {
console.log("Document is in XML mode");
}
Document.xmlVersion is deprecated and removed from DOM Level 4. MDN notes it is no longer supported in Firefox 10.0+. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Deprecated · Legacy
Document.xmlVersion
Removed XML declaration version hook — use createElement tagName detection.
LegacyAvoid in new code
Mozilla FirefoxRemoved since 10.0 (MDN)
No support
Google ChromeMay expose "1.0" · do not rely
Legacy / limited
Apple SafariDo not rely on xmlVersion
Legacy / limited
Microsoft EdgeChromium · prefer MDN trick
Legacy / limited
OperaFollow Chromium behavior
Legacy / limited
Internet ExplorerLegacy DOM XML era
Legacy support
Document.xmlVersionDeprecated / removed
Bottom line: Do not use document.xmlVersion. Detect HTML vs XML with createElement("foo").tagName === "FOO" (MDN) and read contentType when needed.
Wrap Up
Conclusion
Document.xmlVersion was a read-only legacy hook for the XML declaration version. MDN deprecates it, DOM Level 4 removed it, and modern Firefox dropped it long ago. It was rarely useful because it almost always returned "1.0".
Use MDN’s createElement("foo").tagName test for HTML mode
Read document.contentType for MIME type checks
Remove xmlVersion reads when updating legacy scripts
Parse XML with DOMParser for XML string data
Feature-detect with "xmlVersion" in document before legacy reads
❌ Don’t
Read document.xmlVersion in new production code
Assume version info helps you pick parsers today
Confuse xmlVersion with compatMode
Expect support in Firefox 10+ (MDN)
Rely on "1.0" to mean “this is XML”
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about xmlVersion
Deprecated XML declaration version — use createElement detection.
5
Core concepts
📝01
Type
string
Read-only
⚠️02
Status
deprecated
DOM4
📄03
Typical
"1.0"
MDN
✓04
Replace
tagName test
MDN
🐦05
Firefox
removed 10+
MDN
❓ Frequently Asked Questions
A read-only string with the version from the XML declaration (for example "1.0"), or "1.0" if the declaration is absent (MDN). MDN notes it was never very useful because it almost always returned "1.0".
Yes. MDN marks Document.xmlVersion as deprecated. It was removed from the DOM Level 4 specification and is no longer supported in Firefox 10.0 and later.
No. Do not read document.xmlVersion. To detect whether a document is in non-XML HTML mode, MDN recommends checking whether createElement("foo").tagName becomes "FOO" (uppercase).
MDN states the property was never really useful because it always returned "1.0" in practice. XML 1.0 is the only version browsers historically exposed through this legacy DOM hook.
Both are deprecated legacy XML declaration properties on Document. xmlVersion reported the version attribute; xmlEncoding reported the encoding attribute. Use modern APIs instead of either.
No. It is read-only. Even when it existed, you could not change the XML declaration version through this property.
Did you know?
MDN says Document.xmlVersion was never really useful because it almost always returned "1.0". Its main historical purpose was detecting XML vs HTML rendering—but MDN now recommends checking whether document.createElement("foo").tagName becomes "FOO" instead.