Skip to content

Image to Base64 Converter

Turn a PNG, JPG, GIF, WebP or SVG into a Base64 data URI you can paste straight into HTML, CSS or JavaScript. It also works for fonts, CSS and other small files.

Drop a file here

Use images, SVG, text, JSON, CSS, JS, fonts, or other small assets to generate a Data URI instantly.

Images, SVG, CSS, fonts and text files, read in your browser

Generator Controls

Waiting for file or text
Ready. Upload a file or paste text to begin.
StatusWaiting
File / Source—
MIME Type—
Original Size0 B
URI Size0 B
EncodingBase64

Input Workspace & Primary Output

MIME not set Preview idle

Raw Text Input

Editable 0 chars
Waiting for input
No file loaded

Primary Output

Data URI 0 chars
No output yet
Ready to download

File Preview & Snapshot

Upload an image or SVG to preview it here. Other file types will still generate working Data URIs and snippets.
Detected Type—
Extension—
Dimensions—
Base64 Length0
URI Prefix—
SourceText

Ready-to-use snippets

Snippets idle
Generate a Data URI to see code snippets here.

Runs in your browser. Nothing you type, paste or open here is uploaded.

To convert an image to Base64, drop the file on the upload box or choose Select File, then select Generate Data URI. You get a string like data:image/png;base64,iVBORw0KGgo... plus ready-to-paste HTML, CSS and JavaScript snippets. The image is read by your browser, so it's never uploaded.

How to convert an image to Base64

  1. Add the image. Drop a PNG, JPG, GIF, WebP, SVG or ICO file on the upload box, or choose Select File. The MIME Type field fills in from the file.
  2. Name the asset. Type a Variable / Name such as heroLogo. It's used as the JavaScript constant name and the image's alt text; if you leave it blank, the file name is used.
  3. Pick the output. Choose the Primary Snippet: Raw Data URI, HTML <img>, CSS background-image or JavaScript const. All four also appear under Ready-to-use snippets.
  4. Generate and copy. Select Generate Data URI (Ctrl+Enter), then Copy Primary Output, a snippet's own Copy button, or Download .txt.

What is a data:image/png;base64 URI?

A data URI puts a file's contents inside the URL itself, so the browser doesn't make a separate request for it. The format comes from RFC 2397: data:[<media type>][;base64],<data>. For a PNG it looks like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...

image/png is the MIME type, ;base64 says the data is Base64-encoded, and everything after the comma is the image. Every PNG's Base64 starts with iVBORw0KGgo, the encoded PNG signature. You can use the whole string anywhere a URL is expected:

<img src="data:image/png;base64,iVBORw0..." alt="logo">
.icon { background-image: url("data:image/png;base64,iVBORw0..."); }
const logo = "data:image/png;base64,iVBORw0...";

Those are the three snippets the tool writes for you. For non-image files, the HTML snippet becomes a download link instead of an <img> tag.

When to embed images as Base64, and when not to

Base64 turns every 3 bytes into 4 characters, so a data URI is about a third larger than the file. The summary cards show both numbers: Original Size and URI Size. That overhead is worth it for small assets and a poor trade for large ones.

Data URISeparate image file
Extra HTTP requestNoneOne per image
SizeAbout 33% largerOriginal size
Browser cachingCached only with the HTML or CSS around itCached on its own
Good forSmall icons, email signatures, single-file HTML reportsPhotos, large graphics, images used on many pages

A practical rule: inline icons and logos of a few kilobytes, and keep photos as normal files. If the image is large, scale it down first with the image resizer before you convert it.

SVG to data URI: Base64 or URL-encoded

SVG is text, so it doesn't need Base64. With Prefer UTF-8 SVG URI when possible ticked (the default), the tool URL-encodes the markup instead. It swaps double quotes for single quotes (or encodes them as %22 when the SVG already contains single quotes, so nothing breaks), escapes <, >, # and a few other characters, and collapses whitespace. This 110-character SVG:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><circle cx="5" cy="5" r="4" fill="#e11d48"/></svg>

becomes:

data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='4' fill='%23e11d48'/%3E%3C/svg%3E

The encoded body is 124 characters, against 148 for Base64, and it stays readable. Untick the option if a tool you use expects ;base64. Use Load SVG Sample to see the difference on a larger file. You can also paste SVG markup into the text box, set Text Input Mode to SVG markup and generate from that.

Base64 to image: turning a string back into a file

This page only converts files to Base64. To go the other way, paste the string, with or without its data:image/png;base64, prefix, into the Base64 decoder. It works as a Base64 image decoder: it reads the image type from the prefix and Download saves the picture as decoded-image.png or .jpg, .gif, .webp.

To just look at one, paste the full data URI into your browser's address bar and press Enter. Chrome and Firefox show a data:image URI that you paste there yourself, though they block web pages from opening one as a top-level page.

Frequently asked questions

How do I convert an image to Base64?

Select or drop the image on this page and select Generate Data URI. Copy the data URI or one of the HTML, CSS or JavaScript snippets.

Which image formats can I convert?

Any format your browser reads as a file, including PNG, JPG, GIF, WebP, AVIF, BMP, ICO and SVG. Other files, such as WOFF2 fonts or PDFs, also convert to a data URI.

Can this tool convert Base64 back to an image?

No, it only encodes. Paste the Base64 into the Base64 decoder on ToolzyLab, then use Download to save the image file.

Why is my Base64 string bigger than the image?

Base64 uses 4 characters for every 3 bytes, so the output is about 33% larger than the file, plus the short data: prefix.

What is a data URI generator?

It's a tool that reads a file and writes it as a data: URL with the right MIME type, so you can embed the file directly in HTML, CSS or JavaScript. This page is one.

Are my images uploaded?

No. The file is read and encoded by your browser, and the preview is generated locally.

Updated 11 October 2026Reviewed by the ToolzyLab teamHow we test our tools