Web development · 6 min read

Embedding images with Base64 data URIs.

Data URIs let you put an image directly inside HTML or CSS. They save HTTP requests, but add 33% size and lose caching. Here's exactly when to use them.

What a data URI looks like

A data URI is a way of embedding a file directly inside an HTML or CSS document, instead of linking to it as a separate resource. The full form is:

data:[<mime-type>][;base64],<data>

For a small PNG image, that becomes:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...">

The browser sees data: at the start, reads the MIME type, decodes the Base64, and treats the result as if it had downloaded the file. No HTTP request needed.

When data URIs are a good idea

When data URIs are a bad idea

The break-even point

File sizeNetwork savings (1 HTTP request)Verdict
< 1 KBSignificant — request overhead dominatesEmbed
1–4 KBMarginal — depends on whether the image is reusedProfile both
> 4 KBLost to Base64 overhead and lost cachingExternal

SVG: the special case

SVG is text, not binary, so you have a choice: Base64-encode it or URL-encode it directly. URL-encoding produces a smaller result for SVG specifically, because the text already contains many characters that Base64 would inflate.

/* Base64 — works everywhere */
background: url("data:image/svg+xml;base64,PHN2ZyB...");

/* URL-encoded — smaller for SVG */
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'...");

Use the URL-encoded form for SVG when possible; use Base64 for everything else.

Decoding a data URI

Paste the part after base64, into our decoder. The result will be raw bytes — readable as text for SVG/XML/JSON, or as a binary file for PNG/JPEG. Most browsers also let you paste the entire data: URI directly into the address bar to view the embedded resource.

Inspecting a data URI from the wild

If you spot a data:image/... URI on a page and want to know what's inside, copy the part after the comma into the decoder — you'll see the raw bytes, including any PNG signature, JPEG magic number, or SVG markup.

Security note

A data: URI in an <iframe> or <a href> can execute JavaScript if its MIME type is text/html. Modern browsers block top-level navigation to data:text/html for exactly this reason. If you're rendering user-supplied URLs, reject the data: scheme unless you've validated the MIME type.


Published May 2026 · Last reviewed May 2026. Spot an error? Email contactus@base64decode.tools.

Run it yourself

Try the decoder.