Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Note: This feature is available in Web Workers.
The TextEncoder interface enables you to encode a JavaScript string using UTF-8.
Creates and returns a new TextEncoder.
The TextEncoder interface doesn't inherit any properties.
TextEncoder.encoding Read onlyAlways returns utf-8.
The TextEncoder interface doesn't inherit any methods.
TextEncoder.encode()Takes a string as input, and returns a Uint8Array containing the string encoded using UTF-8.
TextEncoder.encodeInto()Takes a string to encode and a destination Uint8Array to put the resulting UTF-8 encoded text into, and returns an object indicating the progress of the encoding. This is potentially more performant than the older encode() method.
This example shows how to encode the "€" character to UTF-8.
| Encoding # interface-textencoder |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jun 28, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.