Encoding API

The Encoding API provides a mechanism for handling text in various character encodings, including legacy non-UTF-8 encodings.

The API provides four interfaces: TextDecoder, TextEncoder, TextDecoderStream and TextEncoderStream.

Note: This feature is available in Web Workers

Interfaces

Polyfill

  • A shim allowing to use this interface in browsers that don't support it.

Specifications

Specification Status Comment
Encoding Living Standard Initial definition.

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
Encoding_API
38
79
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No
25
10.1
38
38
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
Yes
10.3
3.0
TextEncoder
53
Does not accept parameters. Supports only utf-8 encoding.
38-53
Throws RangeError exception for unknown encoding types.
79
Does not accept parameters. Supports only utf-8 encoding.
48
The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.
38-48
If the encoding type label argument is invalid, then a RangeError exception is thrown.
19-38
If the encoding type label argument is invalid, then a TypeError exception is thrown.
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No
25
10.1
38
38
48
The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.
38-48
If the encoding type label argument is invalid, then a RangeError exception is thrown.
19-38
If the encoding type label argument is invalid, then a TypeError exception is thrown.
18
Firefox 18 implemented an earlier and slightly different version of the specification.
?
10.3
3.0
encode
38
79
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No
25
10.1
38
38
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
Yes
10.3
3.0
encodeInto
74
79
66
No
No
14.1
74
74
66
No
14.5
11.0
encoding
38
79
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No
25
10.1
38
38
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
Yes
10.3
3.0
worker_support
38
79
20
No
25
10.1
38
38
20
?
10.3
3.0
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Encoding_API
38
≤79
19
18
Implemented a slightly different version of the spec.
No
25
10.1
38
38
19
18
Implemented a slightly different version of the spec.
25
10.3
3.0
TextDecoder
38
79
19
18
Implemented a slightly different version of the spec.
No
25
10.1
38
38
19
18
Implemented a slightly different version of the spec.
25
10.3
3.0
decode
38
≤79
19
18
Implemented a slightly different version of the spec.
No
25
10.1
38
38
19
18
Implemented a slightly different version of the spec.
25
10.3
3.0
encoding
38
≤79
19
18
Implemented a slightly different version of the spec.
No
25
10.1
38
38
19
18
Implemented a slightly different version of the spec.
25
10.3
3.0
fatal
38
≤79
36
No
25
10.1
38
38
36
25
10.3
3.0
ignoreBOM
38
≤79
63
No
25
10.1
38
38
63
25
10.3
3.0
worker_support
38
≤79
20
No
25
10.1
38
38
20
?
10.3
3.0

BCD tables only load in the browser

TextEncoder

BCD tables only load in the browser

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API