Document: characterSet property
The Document.characterSet
read-only property returns the character encoding of the document that it's currently rendered with.
Note: A "character set" and a "character encoding" are related, but different. Despite the name of this property, it returns the encoding.
Users can override the developer-specified encoding inside the Content-Type header or inline like <meta charset="utf-8">
, such as with Firefox's View → Text Encoding menu. This override is provided to fix incorrect developer-specified encodings that result in garbled text.
Note: The properties document.charset
and document.inputEncoding
are legacy aliases for document.characterSet
. Do not use them any more.
Value
Examples
<button onclick="console.log(document.characterSet);">
Log character encoding
</button>
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
characterSet |
1
1charset alias was made read-only in Chrome 45.
1 |
121212 |
441.51 |
994 |
15charset alias was made read-only in Opera 45.
15≤12.1 |
333 |
1
1charset alias was made read-only in WebView 45.
1 |
18
18charset alias was made read-only in Chrome 45.
18 |
4444 |
14charset alias was made read-only in Opera 45.
14≤12.1 |
111 |
1.0
1.0charset alias was made read-only in Samsung Internet 5.0.
1.0 |