Document.characterSet is a read-only instance property that returns the character encoding label the browser uses to render the page (such as UTF-8). Learn MDN’s encoding-vs-set distinction, the charset alias, how meta tags affect encoding, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
string label
03
Common
UTF-8
04
Alias
charset
05
Source
meta / HTTP
06
Status
Baseline widely
Fundamentals
Introduction
When a browser loads an HTML file, it must decide how to turn bytes into characters. That decision is the document’s character encoding. Modern pages almost always use UTF-8, which supports emoji, accented letters, and scripts from many languages.
document.characterSet lets JavaScript read which encoding label the browser applied—useful for debugging mojibake (garbled text), verifying your <meta charset> tag, or logging locale diagnostics in support tools.
💡
Name vs meaning (MDN)
Despite the property name characterSet, MDN states it returns the encoding, not the abstract character repertoire. A character set and a character encoding are related but not identical.
Document.characterSet is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.characterSet
Read-only encoding label string — essential for UTF-8 verification and i18n debugging.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.characterSetExcellent
Bottom line: Use document.characterSet to read how the browser decoded the page. Declare UTF-8 in HTML and fix server headers when text looks wrong — do not try to set encoding from JavaScript.
Wrap Up
Conclusion
Document.characterSet is the standard read-only way to learn which character encoding label the browser used to render the page. Use it for diagnostics and legacy audits—and fix encoding at the HTML or HTTP layer, not in JavaScript.
Log document.characterSet when debugging garbled text
Use characterSet instead of legacy charset in new code
Align HTTP Content-Type charset with your HTML meta tag
Pair encoding checks with lang attribute review
❌ Don’t
Try to assign a new value to document.characterSet
Assume the property name means “Unicode character repertoire”
Ship new pages without an explicit UTF-8 declaration
Ignore encoding when copying legacy ISO-8859-1 content
Rely on JavaScript to fix bytes decoded with the wrong encoding
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.characterSet
Read-only encoding label — usually UTF-8 on modern sites.
5
Core concepts
📄01
Returns
encoding string
API
✓02
Status
baseline
Standard
🔒03
Access
read-only
DOM
🔄04
Alias
charset
Legacy
🌐05
Fix via
meta / HTTP
HTML
❓ Frequently Asked Questions
A read-only string naming the character encoding the document is currently rendered with — for example UTF-8 or ISO-8859-1.
No. MDN marks Document.characterSet as Baseline Widely available (since July 2015). It is a standard read-only DOM property.
MDN notes that a character set and a character encoding are related but different. Despite the property name, characterSet returns the encoding label the browser uses to interpret bytes.
Yes. document.charset is a legacy alias that returns the same value as document.characterSet. Prefer characterSet in new code for clarity.
Typically the UTF-8 meta tag (<meta charset="utf-8">), the Content-Type HTTP header charset parameter, or a BOM at the start of the file. The browser picks the effective encoding from these signals.
No. It is read-only. To change encoding, fix your HTML meta tag, server headers, or save the file in the correct encoding — not via JavaScript.
Did you know?
Putting <meta charset="utf-8"> within the first 1024 bytes of your HTML helps the browser detect UTF-8 quickly—before it has to guess. That prevents a flash of incorrectly decoded characters on slow connections.