Convert an image to Base64

Drop in an image to get its Base64 code, ready to paste as a data URI, an HTML image tag or a CSS background. The image is encoded in your browser.

How to convert an image to Base64

  1. Choose or drop an image.
  2. Pick the output you need: a data URI, the raw Base64, an HTML tag or a CSS rule.
  3. Click Copy and paste it into your code.

What is Base64?

Base64 is a way of writing binary data, such as an image, using only plain text characters. That lets you put an image directly inside an HTML, CSS, JSON or email file instead of linking to a separate file. A Base64 image wrapped with its type is called a Data URI and looks like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…

When is it worth embedding an image?

  • Small icons and logos in CSS or HTML, to save an extra request to the server.
  • HTML emails and single-file HTML documents that must work without external files.
  • Sending images through APIs or storing them in JSON.
  • Quick prototypes where you do not want to host an image.

When not to use it

Base64 text is about 33% larger than the original file, and embedded images cannot be cached separately by the browser. For photos and anything over a few kilobytes, a normal image file is faster. As a rule of thumb, embed images under about 10 KB and link to the rest. To make an image smaller first, use the image compressor.

How to use the result

  • HTML: <img src="data:image/png;base64,…" alt="">
  • CSS: background-image: url("data:image/png;base64,…");

Frequently asked questions

How do I convert an image to Base64?

Drop the image in and the Base64 code appears straight away. Click Copy to put it on your clipboard.

What is the difference between Base64 and a data URI?

A data URI is the Base64 text with a short prefix that says what kind of file it is, so browsers can display it directly.

Does Base64 make an image bigger?

Yes, by about a third. It is best for small images.

Is my image uploaded?

No. It is encoded locally in your browser.