Image to Base64 Converter — Data URL Encoder & Preview

Turn an image into a base64 data URL you can paste into HTML, CSS or JSON — or paste a data URL to preview it and check its type and size. Everything happens on your device.

—

What this tool does

It converts between an image and the text form of an image. Choose a file and the tool produces a base64 data URL — the data:image/png;base64,… string that can be dropped straight into a web page, a stylesheet or a JSON payload. In the other direction, paste a data URL or a bare base64 string and the tool decodes it, reports the detected image type and the decoded byte size, and renders a preview so you can confirm the payload is intact.

When to inline and when not to

Inlining is best for small, frequently-used assets such as a tiny icon, a favicon, a logo or a spacer — it removes a network request and keeps a single self-contained file. It is a poor fit for photographs and anything large: base64 is about a third bigger than the original bytes, it cannot be cached separately, and a long inline string bloats the HTML or CSS that carries it. A rough guide is to inline only images under a few kilobytes.

The data URL shape

PartExampleMeaning
Schemedata:Marks an inline data URL.
MIME typeimage/pngThe image format.
Encoding;base64The payload is base64 (some data URLs are percent-encoded instead).
DataiVBORw0KGgo…The image bytes, base64-encoded.

Frequently asked questions

What is base64 image encoding?

It is an image written as text. The binary bytes are turned into characters from a 64-symbol alphabet and wrapped in a data URL of the form data:image/png;base64,… . Because the result is text, it can be placed directly in an HTML src, a CSS background or a JSON field with no separate file to host.

Why is the base64 version bigger?

Base64 uses four characters to carry three bytes, so the text is about 33% larger than the original file. For a tiny icon that is irrelevant; for a photograph the inflated inline string is usually the wrong choice, and a normal image file is smaller and cacheable.

Is my image uploaded?

No. A file you choose is read locally by the browser and converted in the page; nothing is sent to a server. You can also paste a data URL or base64 string without choosing a file at all.

How does the tool know the image type?

If the input is a data URL it reads the MIME type from the data: prefix. For a bare base64 string it sniffs the file signature — the magic bytes at the start, such as the PNG or JPEG header — because base64 alone carries no type information.

Why does my data URL not preview?

A preview needs the whole image, not just a fragment, and the data URL must be well-formed. A truncated string, stray whitespace inside the payload, or a MIME type that does not match the bytes will stop the preview even though the base64 may still decode. The tool reports the detected type and decoded size so you can see whether the payload itself is intact.

Can I go the other way, from base64 to an image?

Yes — paste a data URL or base64 into the box and the tool decodes it, shows the detected type and size, and renders a preview. To save it as a file, open the data URL directly in a new tab and save the image from there.

Sources

Everything runs in your browser — your file never leaves your device.