Note: This feature is available in Web Workers.
The Encoding API enables web developers to work with text that is represented in character encodings systems other than the encoding used internally by JavaScript strings. In particular, it enables developers to convert text between JavaScript strings and the UTF-8 encoding that is used for most documents on the web.
It provides two mechanisms:
Note that these operations are asymmetrical: encoding only encodes to UTF-8, while decoding can decode UTF-8 but also many legacy encoding systems.
The API provides synchronous interfaces for encoding and decoding, and also stream-based encoders and decoders, which could be used to, for example, decode text as it arrives over a network connection.
TextDecoderA decoder to convert a byte array containing a particular encoding into a JavaScript string.
TextDecoderStreamA decoder to convert a byte stream containing a particular encoding into a stream of JavaScript strings.
TextEncoderAn encoder to convert a JavaScript string into an array of bytes representing the UTF-8 encoding of the string.
TextEncoderStreamAn encoder to convert a stream of JavaScript strings into an stream of bytes representing the UTF-8 encoding of the strings.
| Specification |
|---|
| Encoding> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
TextDecoder |
38 | 79 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.1 | 38 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.3 | 3.0 | 38 | 10.3 |
Encoding_API |
38 | 79 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.1 | 38 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.3 | 3.0 | 38 | 10.3 |
decode |
38 | 79 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.1 | 38 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.3 | 3.0 | 38 | 10.3 |
encoding |
38 | 79 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.1 | 38 | 1918–19Implemented a slightly different version of the spec. |
25 | 10.3 | 3.0 | 38 | 10.3 |
fatal |
38 | 79 | 36 | 25 | 10.1 | 38 | 36 | 25 | 10.3 | 3.0 | 38 | 10.3 |
ignoreBOM |
38 | 79 | 63 | 25 | 10.1 | 38 | 63 | 25 | 10.3 | 3.0 | 38 | 10.3 |
worker_support |
38 | 79 | 20 | 25 | 10.1 | 38 | 20 | 25 | 10.3 | 3.0 | 38 | 10.3 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
TextEncoder |
38 | 79 | 18 | 25 | 10.1 | 38 | 18 | 25 | 10.3 | 3.0 | 38 | 10.3 |
Encoding_API |
38 | 79 | 18 | 25 | 10.1 | 38 | 18 | 25 | 10.3 | 3.0 | 38 | 10.3 |
encode |
38 | 79 | 18 | 25 | 10.1 | 38 | 18 | 25 | 10.3 | 3.0 | 38 | 10.3 |
encodeInto |
74 | 79 | 66 | 62 | 14.1 | 74 | 66 | 50 | 14.5 | 11.0 | 74 | 14.5 |
encoding |
38 | 79 | 18 | 25 | 10.1 | 38 | 18 | 25 | 10.3 | 3.0 | 38 | 10.3 |
worker_support |
38 | 79 | 20 | 25 | 10.1 | 38 | 20 | 25 | 10.3 | 3.0 | 38 | 10.3 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
TextEncoderStream |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
Encoding_API |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
encoding |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
readable |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
writable |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
TextDecoderStream |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
Encoding_API |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
encoding |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
fatal |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
ignoreBOM |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
readable |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
writable |
71 | 79 | 105 | 58 | 14.1 | 71 | 105 | 50 | 14.5 | 10.0 | 71 | 14.5 |
© 2005–2025 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