Document.xmlEncoding is a deprecated read-only instance property that reported encoding from the XML declaration. Learn when it returns null, MDN’s UTF-16 example, how it differs from characterSet, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
string | null
03
Source
XML decl
04
HTML
Often null
05
Replace
characterSet
06
Status
Deprecated
Fundamentals
Introduction
XML files can start with a declaration such as <?xml version="1.0" encoding="UTF-16"?>. That encoding attribute tells parsers which character encoding the bytes use.
MDN: Document.xmlEncoding returned the encoding as determined by the XML declaration. It should be null if unspecified or unknown. MDN warns not to use this attribute—it was removed from DOM Level 4 and dropped in Firefox 10.0.
💡
HTML vs XML
Normal HTML tutorials use <meta charset="utf-8">, not an XML declaration. On those pages, document.xmlEncoding is typically null. Use characterSet instead.
Document.xmlEncoding 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.xmlEncoding
Removed XML declaration encoding hook — use characterSet for HTML.
LegacyAvoid in new code
Mozilla FirefoxRemoved since 10.0 (MDN)
No support
Google ChromeMay expose null · do not rely
Legacy / limited
Apple SafariDo not rely on xmlEncoding
Legacy / limited
Microsoft EdgeChromium · prefer characterSet
Legacy / limited
OperaFollow Chromium behavior
Legacy / limited
Internet ExplorerLegacy DOM XML era
Legacy support
Document.xmlEncodingDeprecated / removed
Bottom line: Do not use document.xmlEncoding. Read document.characterSet on HTML pages and parse XML declarations explicitly when handling XML files.
Wrap Up
Conclusion
Document.xmlEncoding was a read-only legacy hook for XML declaration encoding. MDN deprecates it, DOM Level 4 removed it, and modern Firefox dropped it long ago. On HTML pages use document.characterSet instead.
Deprecated XML declaration encoding — use characterSet.
5
Core concepts
📝01
Type
string|null
Read-only
⚠️02
Status
deprecated
DOM4
📄03
HTML
null
Typical
✓04
Replace
characterSet
Modern
🐦05
Firefox
removed 10+
MDN
❓ Frequently Asked Questions
A read-only string with the encoding from the XML declaration (for example UTF-16), or null if unspecified or unknown (MDN). On typical HTML pages it is usually null.
Yes. MDN marks Document.xmlEncoding as deprecated. It was removed from the DOM Level 4 specification and is no longer supported in Firefox 10.0 and later.
No. For HTML documents use document.characterSet. For XML data, parse with DOMParser or read the declaration from the source — do not rely on document.xmlEncoding.
HTML documents use meta charset and HTTP headers, not an XML declaration. MDN: xmlEncoding reflects the XML declaration encoding, which HTML pages normally do not have.
xmlEncoding reads the legacy XML declaration encoding on XML documents. characterSet returns the encoding label the browser uses to render the page (MDN Baseline API) — the modern choice for HTML.
No. It is read-only. Even when it existed, you could not set the XML declaration encoding through this property.
Did you know?
MDN’s example shows that <?xml version="1.0" encoding="UTF-16"?> would yield "UTF-16" from document.xmlEncoding on legacy XML documents—but the same MDN page warns the property was removed from DOM Level 4 and dropped in Firefox 10.0. Today’s HTML pages should never depend on it.