GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — TextDecoder: TextDecoder() constructor - Web APIs | MDN

TextDecoder: TextDecoder() constructor

Baseline
Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

  • See full compatibility
  • Learn more

Note: This feature is available in Web Workers.

The TextDecoder() constructor returns a new TextDecoder object.

Syntax

js
new TextDecoder()
new TextDecoder(label)
new TextDecoder(label, options)

Parameters

label Optional

A string identifying the character encoding that this decoder will use. This may be any valid label.

Defaults to "utf-8".

options Optional

An object with the following properties:

fatal Optional

A boolean value indicating if the TextDecoder.decode() method must throw a TypeError when decoding invalid data. It defaults to false, which means that the decoder will substitute malformed data with a replacement character.

ignoreBOM Optional

A boolean value indicating whether the byte order mark will be included in the output or skipped over. It defaults to false, which means that the byte order mark will be skipped over when decoding and will not be included in the decoded text.

Exceptions

RangeError

Thrown if the value of label is unknown, or is one of the values leading to a 'replacement' decoding algorithm ("iso-2022-cn" or "iso-2022-cn-ext").

Examples

js
const textDecoder1 = new TextDecoder("iso-8859-2");

const textDecoder2 = new TextDecoder();

const textDecoder3 = new TextDecoder("csiso2022kr", { fatal: true });
// Allows TypeError exception to be thrown.

const textDecoder4 = new TextDecoder("iso-2022-cn");
// Throws a RangeError exception.

Specifications

Specification
Encoding
# ref-for-dom-textdecoder①

Browser compatibility

See also

  • The TextDecoder interface it belongs to.

Help improve MDN

Learn how to contribute

This page was last modified on Jun 28, 2025 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.