You are here: Reference > JavaScript > client-side > HTML DOM > methods > btoa (window)

btoa method (window)

Browser support:
Creates encoded data from the given string, using base-64 encoding.
Use the atob method to decode a base-64 encoded string. The btoa method uses the A-Z, a-z, 0-9, +, / and = characters for encoding a string.


object.btoa (dataToEncode);
You can find the related objects in the Supported by objects section below.


Required. String that specifies the data to encode.

Return value:

Returns the base-64 encoded string.

Example HTML code 1:

This example illustrates the use of the btoa method:
    <script type="text/javascript">
        function EncodeDecode () {
            input = document.getElementById ("myInput");

            encodedData = window.btoa (input.value);
            alert ("encoded data: " + encodedData);

            decodedData = window.atob (encodedData);
            alert ("decoded data: " + decodedData);
    <input type="text" id="myInput" value="The text to encode"/>
    <button onclick="EncodeDecode ();">Encode in base-64!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content