Encodes the file to a Base64 data URI usable in HTML/CSS
Advertisement
What is a Base64 encoder? A Base64 encoder converts data into a string made of 64 safe text characters (A to Z, a to z, 0 to 9, plus and slash). This tool encodes text as UTF-8 Base64, decodes Base64 back to text, and turns a chosen file into a data URI. It is encoding, not encryption, and it runs in your browser.

What is a Base64 encoder?

Some places only accept plain text: JSON fields, HTTP headers, email bodies, CSS files. Base64 lets you carry binary or awkward data through them by rewriting every three bytes as four letters, digits or symbols. The price is size: the result is about one third larger than the original.

This Base64 encoder and decoder has two modes. Click Encode to Base64 or Decode from Base64, type or paste into the box, then press the main button. Text is handled as UTF-8, so accents, Arabic, Chinese and emoji encode and decode correctly. Under the box, Or encode a file reads any file you choose and outputs a full data URI such as data:image/png;base64,iVBOR..., ready to paste into HTML or CSS.

Know what it does not do. It is standard Base64 only: the URL-safe alphabet with - and _ is not accepted when decoding. Decoding is meant for text, so Base64 that represents an image or other binary data will fail with an invalid input message even if the string itself is valid.

How to encode and decode Base64

  1. Choose Encode to Base64 or Decode from Base64. The label above the box changes to Text to Encode or Base64 to Decode.
  2. Type or paste into the large box. Leading and trailing spaces and line breaks are trimmed before processing.
  3. Click the main button (Encode or Decode). The result appears in the output box with a line showing input length, output length and the size change.
  4. Click Copy above the output to put it on your clipboard.
  5. To embed a file, use Or encode a file and pick it. The box fills with a complete data URI and a line shows the file name, size in bytes and Base64 length.
  6. Use Swap to move the output into the input and flip the mode, which is handy for checking a round trip. Clear empties both boxes.

What this Base64 tool includes

Encode and decode text

Plain text goes in, Base64 comes out, and the reverse. UTF-8 is handled, so non-English characters survive the round trip.

File to data URI

Pick a file and get the whole data:[type];base64,... string, including the file type, which is what a CSS or HTML embed needs.

Size statistics

Each run reports input and output lengths and the percentage change, so you can see the roughly 33 percent growth for yourself.

Swap button

Moves the result back into the input and switches between encode and decode in one click.

Invalid input message

When decoding fails, an alert tells you the input is not a valid Base64 string instead of silently showing garbage.

Read-only output with Copy

The output box is read-only and wraps long strings, so you copy exactly what was produced.

Who uses it, and for what

  • Web developers embedding small assets. Turn a tiny icon or SVG into a data URI and paste it into a stylesheet to save one request. Keep it to small files, because the string is a third larger.
  • API and backend developers. Check a Basic Auth header value, or decode a Base64 field from a JSON response to see what it contains.
  • Support and QA engineers. Paste a suspicious string from a log. If it decodes to readable text, you have found the payload quickly.
  • Email and config editors. Decode a Base64 snippet from a MIME message or a config file. For tokens with three dot-separated parts, use the JWT decoder instead.
  • Students learning encodings. Encode a word, read the result, swap and decode it back. It makes the 3-bytes-to-4-characters idea concrete.

Tips and common errors

  • Base64 is not encryption. Anyone can decode it in seconds, so never use it to hide passwords or keys.
  • Decoding failed? Check for a missing or extra character, quotes copied along with the string, or a URL-safe string containing - or _. Replace those with + and / first.
  • Encoding a file fills the input with the data URI. If you then press Encode, you will encode that text again, which is not what you want. Copy the output instead.
  • Line breaks inside a pasted Base64 string, like the 76-character lines in email, are generally tolerated by the browser decoder, but stray characters such as quotes or a data URI prefix are not. Paste only the Base64 part.
  • Percent signs and plus characters have meaning in URLs. If you put Base64 in a query string, run it through the URL encoder too.
  • Large files make long strings. A data URI beyond a few kilobytes is usually better served as a normal file.

Is it safe? Privacy and limits

Everything runs in your browser. Text you paste is converted by JavaScript on the page, and a file you pick is read locally by the browser instead of being uploaded by this tool. Nothing is stored after you close the tab. Remember that Base64 offers no secrecy: do not paste secrets into any website you do not trust, and treat anything you encode as readable by whoever receives it.

Base64 encoder and decoder FAQ

It turns data into plain text so it can pass through systems built for text. Common cases are data URIs in HTML and CSS, binary values inside JSON, the credentials part of a Basic Authentication header, and attachments in email. Every three bytes become four characters, so the output is about 33 percent larger. It is a transport format, not a way to compress or protect anything, and the receiver must decode it to get the original data.

No. Encryption needs a secret key and cannot be reversed without it. Base64 has no key, so anyone can decode it with a tool like this one. A Basic Auth header looks scrambled, but it is only the username and password in Base64, which is why it should only be sent over HTTPS. If you need real secrecy, use proper encryption and keep the key somewhere safe, not in the same text.

The string may contain characters outside the standard alphabet, such as quotes, a leading data:...;base64, prefix, or the URL-safe - and _. It may also be cut off, or it may decode to binary bytes that are not valid UTF-8 text, such as an image. This tool decodes to text only, so a perfectly valid Base64 string for a PNG will still show the error. For URL-safe input, swap - for + and _ for / first.

Yes. Use the file picker under the text box and choose the image. The box fills with a data URI beginning data:image/png;base64, (or the matching type), which you can paste into an img src or a CSS url(). It works for any file type, not only images. The stats line shows the original size in bytes and the string length, so you can judge whether embedding is worth it.

Yes. Text is converted to UTF-8 bytes before encoding and decoded back as UTF-8, so characters such as é, ñ, Arabic, Chinese and emoji round-trip properly. This matters because the browser's plain btoa function fails on anything outside Latin-1. If you decode a string produced by another tool that used a different text encoding, such as UTF-16 or Latin-1, the result may look wrong even though the Base64 is valid.

Base64 uses 4 characters to represent every 3 bytes, so output is roughly 4/3 the size, plus up to two equals signs of padding at the end. Short strings can grow by a larger percentage because of that padding. The stats line under the output shows the exact change for your input. If size matters, compress the data first and then encode it, or send the file in its raw form instead.

The tool sets no limit, but your browser must read the whole file into memory and show the result in a text box. Files of a few megabytes work but can make the page sluggish, and the string you get is a third larger than the file. For a big file, a command-line tool such as base64 is a better choice. For a data URI in a stylesheet, stick to files of a few kilobytes.

A JWT is three Base64URL parts separated by dots, and this tool will not decode them directly because of the URL-safe alphabet. Paste the whole token into the JWT decoder instead. For text with percent signs such as %20, use the URL encoder and decoder. Picking the right tool avoids confusing errors, because each format uses a different alphabet and different rules. If you are unsure which format you have, look at the characters: dots suggest a JWT, percent signs suggest URL encoding.

Advertisement