atob()
The 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 = atob(encodedData);
Parameters
encodedData-
A binary string contains an base64 encoded data.
Return value
An ASCII string containing decoded data from encodedData.
Exceptions
-
InvalidCharacterErrorDOMException -
Thrown if
encodedDatais not valid base64.
Example
const encodedData = btoa('Hello, world'); // encode a string const decodedData = 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 |
|---|
| HTML Standard (HTML) # dom-atob-dev |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
atob |
4 |
12 |
1
27
atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180). |
10 |
10.5 |
3 |
≤37 |
18 |
4
27
atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180). |
11 |
1 |
1.0 |
worker_support |
30 |
12 |
4 |
10 |
17 |
10 |
4.4 |
30 |
4 |
18 |
10 |
2.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/atob