Encoding

Image to Base64

Choose an image to get its Base64 data URI, ready to paste into CSS or HTML. The file is read on your device and never uploaded.

Ready.

What it does

A data URI embeds a file's bytes directly in text (data:image/png;base64,...) so an image can live inside CSS, HTML or JSON without a separate request.

How to use

  1. Choose an image (up to 10 MB).
  2. Pick the output you need: a full data URI, the Base64 text alone, a CSS background-image rule or an HTML <img> tag.
  3. Copy the result.

When to use it

Base64 makes data about a third larger and cannot be cached separately, so it suits small icons and one-off images. For larger pictures a normal image file is usually better.

Example

Choosing a tiny 1×1 PNG file gives these results, depending on the output format you pick:

Data URI
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==
CSS background
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==");
HTML img tag
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==" alt="">

The Base64 text is the file’s own bytes. The image is not re-compressed or changed, and “Base64 only” gives just the part after base64,. Add a meaningful alt text to the HTML tag yourself.

How much bigger does Base64 make an image?

Base64 writes every 3 bytes as 4 characters, so the data becomes about a third larger, plus a short prefix such as data:image/png;base64,. A 3 KB icon becomes roughly 4 KB of text. Because the image lives inside the file that contains it, the browser cannot cache it separately and it makes that HTML or CSS file larger. That is why data URIs suit small icons and one-off images, and normal image files suit anything bigger.

Practical tips

  • Content-Security-Policy. If your site restricts images, data URIs need img-src data: to be allowed, or the browser will block them.
  • SVG. An SVG is text, so it can also be embedded as a percent-encoded data URI (data:image/svg+xml,…), which is often shorter than Base64. The SVG Optimizer can shrink it first.
  • Large images. Compress a photo before you convert it, for example with the Image Compressor, or keep it as a separate file.

Frequently asked questions

Which images can I convert?

Any image file your browser lets you pick, up to 10 MB. The tool encodes the file as it is.

Does the image leave my device?

No. The file is read in your browser and is never uploaded.

When is a data URI a bad idea?

For large or frequently reused images, because they cannot be cached on their own and they enlarge the page or stylesheet that holds them.

How do I use the CSS output?

Paste the background-image line into a rule for the element, for example inside a class in your stylesheet.

Privacy

This tool runs entirely in your browser. Files you choose are read on your device and are never uploaded.

Share this tool

Your data is not included in this link.