JavaScript Document xmlVersion Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.xmlVersion historically returned the version from the XML declaration (for example <?xml version="1.0"?>), or "1.0" if the declaration was absent (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.xmlVersion. Start with this line.

JavaScript
document.xmlVersion
CallWhat it does
document.xmlVersionPrimary signature.

Built into the browser. Read or assign document.xmlVersion — no import required.

Library declarations
JavaScript
document.xmlVersion

Parameters

ParameterDescription
SetterOptional. Was read-only
Modern pathRequired. createElement tagName check

Return Value

Return ValueDescription
*The current value of document.xmlVersion.

JavaScript Examples

Example 1 — Feature Detect xmlVersion

Many modern engines omit this deprecated property entirely.

JavaScript
const supported = "xmlVersion" in document;
console.log(supported);

if (supported) {
  console.log(document.xmlVersion);
} else {
  console.log("xmlVersion not available");
}
Try It Yourself

How It Works

  1. Use in. Safer than reading a removed property.
  2. Expect gaps. Firefox removed it long ago; others may omit it too.
  3. Do not polyfill. There is nothing useful to restore.
  4. Migrate intent. Use the HTML-mode check instead.

Example 2 — Detect Non-XML HTML Mode (MDN)

The recommended replacement for the old “is this XML?” use case.

JavaScript
if (document.createElement("foo").tagName === "FOO") {
  console.log("Document is not XML"); // HTML mode
} else {
  console.log("Document is XML");
}
Try It Yourself

How It Works

  1. Create a lowercase-named element. createElement("foo").
  2. Read tagName. HTML mode uppercases it to "FOO".
  3. Compare. Equality with "FOO" means non-XML HTML.
  4. XML preserves case. Then tagName stays "foo".

Example 3 — Safe Legacy Read (Audit Only)

Only for understanding old pages — never for new features.

JavaScript
const version =
  "xmlVersion" in document ? document.xmlVersion : null;

console.log(version); // "1.0" | null | other legacy string
console.log("Prefer createElement tagName check");
Try It Yourself

How It Works

  1. Guard first. Only read when the property exists.
  2. Expect "1.0". MDN: that was effectively the only useful answer.
  3. Treat as archaeology. Useful for audits, not product logic.
  4. Point forward. Log a reminder to use the modern check.

Browser Support

Document.xmlVersion is Deprecated (MDN). It was removed from DOM Level 4 and is not implemented in Firefox 10+. Do not rely on it.

✓ Deprecated · Avoid

Document.xmlVersion

Legacy XML declaration version string — removed from the modern DOM path.

Legacy Avoid in new apps
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
xmlVersion Deprecated

Bottom line: Safe only as historical knowledge. For HTML vs XML mode, use the createElement tagName check; for encoding/type, use characterSet and contentType.

Frequently Asked Questions

Historically, the version from the XML declaration (for example "1.0"), or "1.0" if the declaration was absent (MDN). In practice it almost always returned "1.0".
Yes. MDN marks Document.xmlVersion as Deprecated. It was removed in DOM Level 4, and Firefox 10+ no longer implements it.
No. To detect non-XML HTML mode, MDN recommends: document.createElement("foo").tagName === "FOO".
MDN: it always returned "1.0", so it could not tell you anything meaningful about the document.
Both are deprecated legacy XML declaration properties. xmlVersion reported the version; xmlEncoding reported the encoding. Prefer modern APIs instead.
No. It was read-only. Even when present, you could not change the XML declaration through this property.

Next: afterscriptexecute

Learn the Document event fired after a script executes.

afterscriptexecute tutorial →

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.

11 people found this page helpful