JavaScript Document xmlVersion Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Instance property

What You’ll Learn

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

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).

Related Document tutorials: xmlEncoding, compatMode, contentType, Document constructor.

Understanding Document.xmlVersion

A read-only instance property from the legacy DOM XML era.

  • Value — version string from XML declaration (MDN), e.g. "1.0".
  • Default"1.0" when the declaration is absent (MDN).
  • Low utility — MDN: almost always returned "1.0".
  • Read-only — you cannot assign a new version here.
  • Deprecated — removed from DOM Level 4; not in Firefox 10+ (MDN).

📝 Syntax

JavaScript
document.xmlVersion

Value

A string (MDN). Typically "1.0".

MDN XML declaration example

XML
<?xml version="1.0"?>
<!-- document.xmlVersion would be "1.0" on legacy XML docs -->

⚡ Quick Reference

GoalCode / note
Read (legacy)document.xmlVersion
Default when absent"1.0" (MDN)
Detect HTML modedocument.createElement("foo").tagName === "FOO"
Detect XML modedocument.createElement("foo").tagName === "foo"
Feature-detect"xmlVersion" in document
MDN statusDeprecated

🔍 At a Glance

Four facts about document.xmlVersion.

Type
string

Read-only

Typical
"1.0"

Almost always

Utility
low

MDN note

Status
deprecated

DOM4 removed

📋 xmlVersion vs xmlEncoding

document.xmlVersiondocument.xmlEncoding
XML declaration partversion attributeencoding attribute
Typical value"1.0"null on HTML
MDN utilityLow — almost always 1.0Low — use characterSet
MDN statusDeprecatedDeprecated

Examples Gallery

Examples follow MDN Document: xmlVersion. On HTML try-it pages, the property may be missing (Firefox) or return "1.0" in some legacy engines.

📚 Getting Started

Read the deprecated property and interpret the result.

Example 1 — Read document.xmlVersion

Log the property on the current document.

JavaScript
console.log(document.xmlVersion);
// May be undefined (Firefox 10+) or "1.0" in some browsers
Try It Yourself

How It Works

MDN: returns version from XML declaration or "1.0" when absent—but avoid relying on it.

Example 2 — MDN: Version from XML Declaration

When a document starts with version="1.0", legacy browsers returned "1.0".

Concept
<?xml version="1.0"?>
<root/>
JavaScript
// Legacy XML document (MDN):
console.log(document.xmlVersion); // "1.0"
Try It Yourself

How It Works

MDN notes this was rarely informative because the value was almost always "1.0".

📈 Compare, Detect & Modern Pattern

Pair with xmlEncoding and use MDN’s HTML detection trick.

Example 3 — Compare with document.xmlEncoding

Both properties came from the legacy XML declaration era.

JavaScript
console.log({
  xmlVersion: document.xmlVersion,
  xmlEncoding: document.xmlEncoding
});
// Typical HTML: { xmlVersion: "1.0" | undefined, xmlEncoding: null }
Try It Yourself

How It Works

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");
}
Try It Yourself

How It Works

In HTML mode, unknown tag names are uppercased. In XML mode, they stay lowercase (MDN).

Example 5 — Modern Helper: isHtmlDocument()

Wrap MDN’s detection in a reusable function instead of reading xmlVersion.

JavaScript
function isHtmlDocument(doc) {
  return doc.createElement("foo").tagName === "FOO";
}

console.log({
  isHtml: isHtmlDocument(document),
  contentType: document.contentType
});
Try It Yourself

How It Works

Combine tagName detection with contentType for clearer diagnostics.

🚀 Why This Property Existed

  • Legacy XML documents — read declaration version from the DOM (historical).
  • HTML vs XML sniffing — replaced by MDN’s createElement tagName test.
  • Migration audits — find xmlVersion reads and remove them.
  • Old tutorials — understand pre-DOM4 XML Document APIs.
  • Not informative — MDN: almost always returned "1.0".
  • Firefox note — removed since Firefox 10.0 (MDN).

🧠 How to Detect Document Mode Today

1

Skip xmlVersion

Deprecated and removed from DOM Level 4 (MDN).

Avoid
2

Create test element

document.createElement("foo") with a lowercase name.

MDN
3

Compare tagName

"FOO" means non-XML HTML mode; "foo" means XML mode.

Detect
4

Optional: contentType

Confirm with document.contentType (e.g. "text/html").

📝 Notes

  • MDN: Deprecated — do not use; removed from DOM Level 4.
  • Firefox: not supported since version 10.0 (MDN warning).
  • Returns "1.0" when XML declaration is absent (MDN).
  • MDN: property was never really useful—almost always "1.0".
  • HTML vs XML: use createElement("foo").tagName === "FOO" (MDN).
  • Related: xmlEncoding, compatMode, contentType.

Legacy Browser Support

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.

Legacy Avoid in new code
Mozilla Firefox Removed since 10.0 (MDN)
No support
Google Chrome May expose "1.0" · do not rely
Legacy / limited
Apple Safari Do not rely on xmlVersion
Legacy / limited
Microsoft Edge Chromium · prefer MDN trick
Legacy / limited
Opera Follow Chromium behavior
Legacy / limited
Internet Explorer Legacy DOM XML era
Legacy support
Document.xmlVersion Deprecated / removed

Bottom line: Do not use document.xmlVersion. Detect HTML vs XML with createElement("foo").tagName === "FOO" (MDN) and read contentType when needed.

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".

Continue with parseHTML(), xmlEncoding, contentType, or the JavaScript hub.

💡 Best Practices

✅ Do

  • 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”

Key Takeaways

Knowledge Unlocked

Five things to remember about xmlVersion

Deprecated XML declaration version — use createElement detection.

5
Core concepts
⚠️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.

Next: parseHTML()

Learn the XSS-safe static method that parses an HTML string into a new Document.

parseHTML() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful