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 arbitrary Unicode strings, see The "Unicode Problem" section of the Base64 glossary entry.
Syntax
Parameters
-
encodedData
-
A binary string (i.e., a string in which each character in the string is treated as a byte of binary data) containing base64-encoded data.
Return value
An ASCII string containing decoded data from encodedData
.
Exceptions
InvalidCharacterError
DOMException
-
Thrown if encodedData
is not valid base64.
Examples
const encodedData = btoa("Hello, world");
const decodedData = atob(encodedData);
Specifications
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 |
10 |
10.5 |
3 |
≤37 |
18 |
4 |
11 |
1 |
1.0 |
worker_support |
30 |
12 |
4 |
10 |
17 |
10 |
4.4 |
30 |
4 |
18 |
10 |
2.0 |
See also