Web/API/WindowOrWorkerGlobalScope/atob

From Get docs

The WindowOrWorkerGlobalScope.atob() function decodes a string of data which has been encoded using Base64 encoding. You can use the btoa() method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the atob() method to decode the data again. For example, you can encode, transmit, and decode control characters such as ASCII values 0 through 31.

For use with Unicode or UTF-8 strings, see the note on "Unicode strings" in the page for btoa().

Syntax

var decodedData = scope.atob(encodedData);

Parameters

encodedData
A binary string contains an base64 encoded data.

Return value

An ASCII string containing decoded data from encodedData.

Exceptions

DOMException (name
InvalidCharacterError)
Throws if encodedData is not valid base64.

Example

const encodedData = window.btoa('Hello, world'); // encode a string
const decodedData = window.atob(encodedData); // decode the string

Polyfill

You can use a polifill from https://github.com/MaxArt2501/base64-js/blob/master/base64.js for browsers that don't support it.

Specifications

Specification Status Comment
HTML Living StandardThe definition of 'WindowOrWorkerGlobalScope.atob()' in that specification. Living Standard Method moved to the WindowOrWorkerGlobalScope mixin in the latest spec.
HTML 5.1The definition of 'WindowBase64.atob()' in that specification. Recommendation Snapshot of HTML Living Standard. No change.
HTML5The definition of 'WindowBase64.atob()' in that specification. Recommendation Snapshot of HTML Living Standard. Creation of WindowBase64 (properties where on the target before it).

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
atob Chrome

Full support 4

Edge

Full support 12

Firefox Full support 1


Full support 1


Full support 27

Notes'

Notes' atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180). Full support 57

Notes'

Notes' atob() now defined on WindowOrWorkerGlobalScope mixin.

IE

Full support 10

Opera

Full support 10.5

Safari

Full support 3

WebView Android

Full support ≤37

Chrome Android

Full support 18

Firefox Android Full support 4


Full support 4


Full support 27

Notes'

Notes' atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180). Full support 57

Notes'

Notes' atob() now defined on WindowOrWorkerGlobalScope mixin.

Opera Android

Full support 11

Safari iOS

Full support 1

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
See implementation notes.'
See implementation notes.


See also