All Tools

Image to Base64 Converter, Data URL and CSS Snippets

Turn a PNG, JPEG, WebP, GIF, BMP or AVIF image into Base64, a data URL, an img tag or a CSS url(), with sizes and one-click copy. Paste Base64 to get the picture back. Nothing is uploaded.

Direction

Drag an image here, paste, or choose

One image, up to 10 MB. PNG, JPEG, WebP, GIF, BMP and AVIF files. Nothing is uploaded.

Need to encode text or any other file? Use the Base64 encoder and decoder, or change the format with the image converter.


About the Image to Base64 converter

The Image to Base64 converter turns a picture into text that you can paste into HTML, CSS, JSON or an email template. Choose an image, and the page gives you four things at once: the Base64 string, a ready-to-use data URL, an HTML <img> tag and a CSS url(), each with its own Copy button. It also shows the file size, the size of the text and how much bigger the text is. Everything happens in your browser. Your image never leaves your device, nothing is uploaded, and there is no account.

The same page works the other way round. Switch the direction to Base64 to image, paste a Base64 string, a data URL, an <img> tag or a url(data:...) rule, and you get the picture back with its real type, its size in pixels and a download button. The page at Base64 to Image opens on that direction.

How to use it

Steps

  1. Choose an image, drop it on the page or paste it. PNG, JPEG, WebP, GIF, BMP and AVIF files up to 10 MB work.
  2. Check the preview, the dimensions and the three sizes.
  3. Press Copy next to the output you need: the bare string, the data URL, the <img> tag or the CSS url().
  4. Paste it where it belongs, for example into the src of an image, a background-image rule or a JSON field.

What the four outputs are

  • Base64 string: only the encoded bytes, with no prefix. Use it for an API field or a config value that expects plain Base64.
  • Data URL: the string with the prefix data:image/png;base64, so that a browser reads it as a picture. It works in an <img src>, a CSS url(), a link or the address bar.
  • HTML <img> tag: <img src="data:..." alt="">. Add a meaningful alt text before you publish it.
  • CSS url(): url("data:..."), ready for background-image, list-style-image or content.

The type in the prefix is read from the first bytes of the file, not from its name. A JPEG saved as photo.png therefore gets data:image/jpeg;base64,, which is what a browser expects.

The maths of the size

Base64 writes every group of three bytes, which is 24 bits, as four characters of six bits each. For an image of nn bytes the text is

L=4⌈n3⌉L = 4 \left\lceil \frac{n}{3} \right\rceil

characters long, padding with = when nn is not a multiple of 3. The overhead is the extra size compared with the file:

overhead=Ln−1\text{overhead} = \frac{L}{n} - 1

For a size that divides by 3 this is exactly 43−1=33.3 %\tfrac{4}{3} - 1 = 33.3\ \%. Other sizes cost a little more because of the padding.

Worked example

Take an icon of 300 bytes. It divides by 3 into 100 groups, so the text is 4×100=4004 \times 100 = 400 characters, and the overhead is 400/300−1=33.3 %400 / 300 - 1 = 33.3\ \%. Now take an image of 1,000 bytes. It needs ⌈1000/3⌉=334\lceil 1000 / 3 \rceil = 334 groups, so the text is 4×334=13364 \times 334 = 1336 characters and the overhead is 1336/1000−1=33.6 %1336 / 1000 - 1 = 33.6\ \%. The page shows these numbers for your own file, so you can decide whether embedding is worth it.

When embedding makes sense

A data URL saves a request and keeps the picture inside the page, which helps for small icons, a tiny logo in an email, a placeholder while the real image loads or a single-file HTML document. For larger pictures a normal file is usually better: the browser can cache a file on its own, but it cannot cache a data URL apart from the page or stylesheet that holds it, and the text is a third bigger than the file. If a picture is too big, shrink it first with the Image Resizer or save it in a lighter format with the Image Converter.

Limits worth knowing

Each image can be up to 10 MB, and the page says so clearly when a file is larger, instead of encoding half of it. SVG is not supported in this version, because an SVG is text and is usually better embedded as it is. A very long output is cut on screen after the first 20,000 characters so the page stays fast, and the page tells you how many there are in total. Copy always copies the complete value.

Privacy

The file is read and encoded by your browser, on your device. The Base64 text is built there too and is never sent anywhere, so it is safe to use with private pictures, screenshots and internal logos. Nothing is stored once you close the tab.

Related tools

To encode text or any other file, use the Base64 encoder and decoder. To change the format of a picture first, use the Image Converter. To shrink it, use the Image Resizer.

Frequently asked questions

Why is the Base64 text about a third bigger than the image?

Base64 writes every three bytes as four characters, so the text is 4 × ceil(n ÷ 3) characters long for n bytes. A file whose size divides by 3 grows by exactly 33.3 percent, and other sizes grow slightly more because of the equals-sign padding. The page shows the file size, the text size and the overhead for your image.

When is it a good idea to embed an image as a data URL?

It suits small images such as icons, a tiny logo in an email template or a placeholder, because it saves one request and the picture travels with the page. For anything larger, a normal file is better: the browser cannot cache a data URL separately from the page that holds it, and the text is a third bigger than the file.

What do the four outputs contain?

The Base64 string is the payload alone. The data URL adds the prefix data:image/png;base64, so a browser can read it as a picture. The img tag and the CSS url() are ready to paste into HTML or a stylesheet, and both hold the same data URL. Each one has its own Copy button.

Which image formats and sizes can I encode?

PNG, JPEG, WebP, GIF, BMP and AVIF files up to 10 MB each. The type is read from the first bytes of the file, not from its name, so a JPEG saved as photo.png gets an image/jpeg data URL. SVG is not supported in this version, and the page says so when you choose one.

Is my image uploaded to a server?

No. The file is read and encoded by your browser on your own device, and the Base64 text is built there too. Nothing is sent over the network and nothing is stored once you close the tab.

Why is only part of a long output shown on screen?

A large image makes millions of characters, and a text box that long would make the page slow. The box shows the first 20,000 characters and says how many there are in total. The Copy button always copies the complete value, so what you paste is never cut.

Other related tools