Window btoa() method

Definition and usage

btoa() The method encodes the string in base-64.

btoa() The method encodes the string using the characters "A-Z", "a-z", "0-9", "+", "/", and "=".

Tip:Please use atob() method The method decodes base-64 encoded strings.

See also:

atob() method

Example

Encode string in base-64:

let text = "Hello World!";
let encoded = window.btoa(text);

Try it yourself

Syntax

window.btoa(string)

Parameter

Parameter Description
string Required. The string to be encoded.

Return value

Type Description
String Base-64 Encoded String.

Browser Support

All Browsers Support btoa():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 10-11 Support Support Support Support