Window: atob() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The atob()
method of the Window
interface decodes a
string of data which has been encoded using Base64 encoding. You can use
the Window.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" in the Base64 glossary entry.
Syntax
atob(encodedData)
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 = window.btoa("Hello, world"); // encode a string
const decodedData = window.atob(encodedData); // decode the string
Specifications
Specification |
---|
HTML Standard # dom-atob-dev |
Browser compatibility
BCD tables only load in the browser
See also
- A polyfill of
atob
is available incore-js
data
URLsWorkerGlobalScope.atob()
: the same method, but in worker scopes.Window.btoa()