The WindowOrWorkerGlobalScope.atob() function decodes a string of data which has been encoded using base-64 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 this note at Base64 encoding and decoding and this note at btoa().

Syntax

var decodedData = scope.atob(encodedData);

Throws

Throws a DOMException if the length of passed-in string is not a multiple of 4.

Example

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

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox 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 10Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? 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 ? Safari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also