Image to Base64

Convert an image to Base64: data URI, HTML, CSS and Markdown snippets, size overhead and when inlining pays off.

loading Image to Base64
About this tool

Image to Base64: what you get

Base64 writes the bytes of a file with 64 printable characters, so an image can live inside text: an HTML page, a CSS file, a JSON document or an email. With the prefix data:image/png;base64, in front, the text becomes a data URI that a browser opens like a normal image address. The conversion happens in your browser: the image is read, encoded and shown here, and never uploaded. This page opens the tool in the image to Base64 direction, with a sample picture loaded.

Worked example: a small SVG

This 120 × 60 picture is 170 bytes of SVG text and becomes 228 Base64 characters:

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiPjxyZWN0IHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiIHJ4PSI4IiBmaWxsPSIjMWMyNDMwIi8+PGNpcmNsZSBjeD0iMzAiIGN5PSIzMCIgcj0iMTgiIGZpbGw9IiNmMmI4NGUiLz48L3N2Zz4=

And the three snippets the tool copies for it:

<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiPjxyZWN0IHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiIHJ4PSI4IiBmaWxsPSIjMWMyNDMwIi8+PGNpcmNsZSBjeD0iMzAiIGN5PSIzMCIgcj0iMTgiIGZpbGw9IiNmMmI4NGUiLz48L3N2Zz4=" alt="">
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiPjxyZWN0IHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiIHJ4PSI4IiBmaWxsPSIjMWMyNDMwIi8+PGNpcmNsZSBjeD0iMzAiIGN5PSIzMCIgcj0iMTgiIGZpbGw9IiNmMmI4NGUiLz48L3N2Zz4=");
![](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiPjxyZWN0IHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiIHJ4PSI4IiBmaWxsPSIjMWMyNDMwIi8+PGNpcmNsZSBjeD0iMzAiIGN5PSIzMCIgcj0iMTgiIGZpbGw9IiNmMmI4NGUiLz48L3N2Zz4=)

How much bigger Base64 is

Base64 turns every 3 bytes into 4 characters, so the text is about one third larger than the file (plus the prefix):

File sizeBase64 charactersOverhead
1 KB136833.6%
5 KB682833.4%
10 KB1365633.4%
100 KB13653633.3%
1024 KB139810433.3%

When inlining pays off

  • Small icons and logos (a few KB): you save a request, and the file travels with the page.
  • HTML emails and single-file pages, where nothing else can be fetched.
  • Not for photos: a 200 KB image becomes about 267 KB of text that the browser cannot cache separately, and it slows the page that carries it. Compress first, or serve a file.

How to use the converter

  1. Drop an image on the box, paste it with Ctrl+V or pick a file; the sample button loads an example.
  2. Choose whether the result keeps the data:image/...;base64, prefix.
  3. Copy the Base64, or the ready-made HTML, CSS or Markdown line.

Frequently asked questions

How do I convert an image to Base64?

Drop it on the tool: it reads the bytes and writes them in Base64, with the data URI prefix if you want it. Nothing is uploaded.

Is Base64 a way to compress or protect an image?

Neither: it makes the data a third larger, and anyone can decode it back. It is only a way to carry binary as text.

Which image types work?

PNG, JPEG, WebP, GIF, BMP, AVIF and SVG. The data URI carries the right type (image/png, image/svg+xml…) so that the browser knows how to draw it.

Report a problem