X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Window btoa() Method

Window Object Reference Window Object

Example

Encode a string in base-64:

var str = "Hello World!";
var enc = window.btoa(str);

var res = "Encoded String: " + enc;
document.getElementById("demo").innerHTML = res;

The result of res will be:

Encoded String: SGVsbG8gV29ybGQh

Try it yourself »


Definition and Usage

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

This method uses the "A-Z", "a-z", "0-9", "+", "/" and "=" characters to encode the string.

Tip: Use the atob() method to decode a base-64 encoded string.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The btoa() method is supported in all major browsers.


Syntax

window.btoa(str)

Parameter Values

Parameter Description
str Required. The string to be encoded

Return Value

Type Description
String The base-64 encoded string


Window Object Reference Window Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook