Image to Base64 Converter

Encode a PNG, JPG, SVG, WebP or GIF file as Base64 text that you can paste straight into HTML, CSS, JSON or a configuration file.

How to convert an image to Base64

  1. Choose an image, drop it onto the page or paste it from the clipboard. The Base64 output appears immediately.
  2. Pick the output format: a complete data URI, raw Base64 only, a ready-made CSS background-image rule, or an HTML <img> tag. Switching the format updates the text instantly.
  3. Click Copy to clipboard, or Download as .txt if the string is too long to handle comfortably.

How the encoder works

Unlike the other tools on this site, the Base64 converter does not redraw your image. It reads the original file with the browser’s FileReader.readAsDataURL() function, which returns the file as data:<type>;base64,<data>. Base64 represents every 3 bytes of the file with 4 characters from a 64-character alphabet (A–Z, a–z, 0–9, “+” and “/”), adding “=” as padding at the end when needed.

Because the encoding is exact, decoding the text gives back an identical copy of the file, byte for byte. That has two consequences. First, the image is not compressed or altered in any way; if you want a smaller string, shrink the image first with Compress Image or Resize Image. Second, any metadata in the file, such as EXIF camera details or GPS coordinates in a phone photo, is included in the Base64 text too.

The text is always about a third larger than the file: 4 characters for every 3 bytes, plus the short data:image/...;base64, prefix in the data URI formats. The line under the output shows the exact number of characters and the overhead for your file.

The four output formats

When inline images make sense, and when they do not

Embedding an image as Base64 saves the browser a separate request for the file. That mattered a lot when browsers could fetch only a few files at a time; with modern HTTP/2 and HTTP/3 connections the benefit is much smaller, while the costs remain:

A practical rule of thumb: inline images only when they are a few kilobytes at most, and link to regular image files for everything else.

A tip for SVG files

SVG images are text already, so Base64 makes them about a third bigger and unreadable. In CSS you can often use a URL-encoded SVG instead, for example url("data:image/svg+xml,%3Csvg xmlns=..."), which is usually shorter than the Base64 version and still easy to edit. Base64 remains the simplest option when a system specifically expects Base64 data.

Limitations

Frequently asked questions

Why is the Base64 string larger than my image file?

Base64 uses 4 text characters for every 3 bytes of data, so the encoded text is about 33% larger than the file, plus a short prefix in the data URI formats.

What is the difference between a data URI and raw Base64?

A data URI adds a prefix with the file type, for example data:image/png;base64, so browsers can use it directly as an image URL. Raw Base64 is only the encoded data, which is what many APIs and databases expect.

Does Base64 encoding compress or change my image?

No. The file is encoded byte for byte, including any metadata. To get a shorter string, compress or resize the image before encoding it.

Is Base64 a form of encryption?

No. Base64 is an encoding, not encryption. Anyone can decode the text back into the original image, so it does not protect private pictures.

Should I embed images as Base64 in my website?

Only small ones, such as icons of a few kilobytes. Large inline images make HTML and CSS files heavier, cannot be cached separately and can delay page rendering.

Can I convert SVG files?

Yes. For use in CSS, a URL-encoded SVG data URI is often shorter than Base64, but Base64 works everywhere a data URI is accepted.

Is my image uploaded to a server?

No. The file is read and encoded by your browser, and the image and the resulting text stay on your device.

Related tools

Related guides