Encoding API

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

The API provides two interfaces: TextDecoder and  TextEncoder.

Reference

 

Tutorials & tools

  • A shim allowing to use this interface in browsers that don't support it.
  • StringView – a C-like representation of strings based on typed arrays.

Specifications

Specification Status Comment
Encoding Living Standard Initial definitions.

Browser compatibility

TextDecoder

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support38 ?

19

181

No2510.1
Available in workers38 ?20 No25 ?
TextDecoder() constructor38 ?

19

181

No2510.1
decode38 ?

19

181

No25 No
encoding38 ?

19

181

No25 No
fatal ? ? ? ? ? ?
ignoreBOM ? ? ? ? ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support3838 ?

19

181

? No ?
Available in workers3838 ?20 ? No ?
TextDecoder() constructor3838 ?

19

181

? No ?
decode3838 ?

19

181

? No ?
encoding3838 ?

19

181

? No ?
fatal ? ? ? ? ? ? ?
ignoreBOM ? ? ? ? ? ? ?

1. Implemented a slightly different version of the spec.

TextEncoder

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support38 ?

19

181

No25 No
Available in Web Workers38 ?20 No25 No
TextEncoder() constructor

532

38 — 533

?

484

38 — 485

19 — 386

181

No25 No
encoding38 ?

19

181

No25 No
encode38 ?

19

181

No25 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support3838 ?

19

181

? No ?
Available in Web Workers3838 ?20 ? No ?
TextEncoder() constructor3838 ?

484

38 — 485

19 — 386

181

? No ?
encoding3838 ?

19

181

? No ?
encode3838 ?

19

181

? No ?

1. Firefox 18 implemented an earlier and slightly different version of the specification.

2. Does not accept parameters. Supports only utf-8 encoding.

3. Throws RangeError exception for unknown encoding types.

4. The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.

5. If the encoding type label argument is invalid, then a RangeError exception is thrown.

6. If the encoding type label argument is invalid, then a TypeError exception is thrown.

Document Tags and Contributors

Last updated by: fscholz,