Image to Base64

Converts an image to a Base64 data URI and back, entirely in your browser. The encoded string can be pasted straight into HTML, CSS, JSON or an email template with no separate file to host.

Live demo · real result from this tool

Drop your image here

or paste with Ctrl+V · nothing is uploaded · add several to process them in one go

Your result appears here — processed on your device.

Processed on your device — nothing is uploaded.

How to use Image to Base64

  1. Choose an image to encode, or paste a data URI to decode.
  2. Copy the data URI, or download the decoded image.
  3. Paste it into an img src, a CSS background-image, or your template.
  4. Encoded output is about 33% larger than the original file.
  5. Keep the data:image/…;base64, prefix and make sure its media type matches the real format.
  6. The file is read locally — nothing is uploaded.

What you gain and what you pay

You gain one fewer network request, an asset that cannot 404, and a file that travels inside the document. You pay about 33% in size, because Base64 encodes three bytes as four characters, and you lose separate caching — an inlined image is re-downloaded with every page that embeds it, where a normal file is fetched once and cached across the whole site. That trade is good for something small and bad for a photograph.

Where inlining is genuinely the right answer

Email templates, where externally hosted images are blocked by default in most clients. Single-file HTML documents meant to be archived or emailed. Tiny icons in a stylesheet. Low-quality image placeholders shown while the real photograph loads. Anything that must work with no network at all. The rough threshold is a few kilobytes: below it, inlining usually wins; above it, a normal cached file does.

Reading a data URI

The format is data:[media type];base64,[payload]. The media type must be right — an image/png prefix on JPEG bytes will not display, and this is the commonest reason a pasted data URI shows nothing. The payload is the file’s bytes, unchanged, so decoding gives you back a byte-identical image; Base64 is a re-encoding, never a lossy step.

SVG does not need this

An SVG is already text. Base64-encoding one makes it a third larger for no benefit — either inline the markup directly into your HTML, where CSS can then style it, or use a URL-encoded data URI, which is smaller than Base64 and still works in CSS. Reserve this tool for raster formats.

Frequently asked questions

Does it give me the HTML or CSS code?
Yes. You get the full data URI, plus an img tag and a CSS background-image line that use it. The snippets are shortened on screen, so copy the full URI from the first box. The encoded length and the size overhead are shown too.
Is my data secure?
Absolutely. This tool runs 100% locally in your browser. Your files are never uploaded to any server.
When should I inline an image as Base64?
For small assets — icons, tiny placeholders, images in email templates — where saving a request is worth the 33% size increase and the loss of caching. For anything larger than a few kilobytes, a normal file that the browser can cache is better.
Does Base64 encoding reduce image quality?
No. It is a lossless re-encoding of the exact bytes, so decoding returns an identical file. It only changes the size of the representation, upward by about a third.
Why is my data URI not displaying?
Most often the media type in the prefix does not match the actual format — data:image/png in front of JPEG bytes will not render. After that: a truncated payload, or a line break inserted somewhere in the string when it was copied.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close