A Base64 data URI encodes an image as text, letting you embed it directly in an HTML tag, a CSS rule, or a JSON payload with no separate file and no extra network request. It is a genuinely useful technique for small assets — and a mistake for large ones.
How to use the Image to Base64
- Upload the image you want to encode
- Copy the generated data URI, or just the raw Base64 if you need it without the prefix
- Paste it into your HTML src, CSS url(), or JSON field
When embedding is worth it
Every external image costs a separate HTTP request. For a handful of tiny assets — icons, a 1px gradient, a small logo in an email template — inlining removes that round trip and can render faster.
The catch is that Base64 inflates the data by roughly 33%, and inlined images cannot be cached separately from the document that contains them. A 500 KB background image inlined into your CSS means every visitor downloads 665 KB of CSS on every cache miss, and the browser cannot start rendering until it arrives.
A practical rule: inline below about 5 KB, link above it.
Using a data URI
In HTML:
<img src="data:image/png;base64,iVBORw0KG…" alt="">In CSS:
.icon { background-image: url("data:image/png;base64,iVBORw0KG…"); }The data:image/png;base64, prefix is part of the URI and must be included. The MIME type has to match the actual image format or the browser will refuse to render it.
The real cost of an inlined image
A data URI removes one network request. That is the entire benefit, and against it sit several costs that are easy to underestimate.
33% larger. Base64 encodes three bytes as four characters. A 100 KB image becomes about 133 KB of text.
Not cached separately. This is the big one. A linked image is downloaded once and reused across every page; an inlined one is part of the HTML or CSS and is re-downloaded on every page load that is not itself cached.
Render-blocking in CSS. A stylesheet blocks first paint. A 200 KB inlined image inside it delays the page appearing at all, for every visitor.
No parallel loading. Linked images download alongside everything else; inlined ones arrive in sequence as part of the document.
Larger HTML means slower parsing and more memory, which is most noticeable on low-end phones.
HTTP/2 made additional requests much cheaper, which weakened the one advantage considerably. The sensible threshold is now around 2–4 KB: below it, inline; above it, link. SVG icons and tiny placeholders qualify. Photographs essentially never do.
Where a data URI genuinely is the right answer
A handful of situations favour inlining regardless of the size arithmetic.
A single-file deliverable. An HTML report, an email template, or a page that must work when opened from a local folder with no accompanying assets. If the file has to survive being emailed around, everything must be inside it.
Critical above-the-fold imagery. A small logo or a low-quality image placeholder inlined into the initial HTML appears immediately rather than after a round trip. The LQIP pattern — a tiny blurred version inlined, replaced by the real image once loaded — exists precisely for this.
Avoiding a flash of missing content. Small icons that appear immediately on load, where a request round trip would show an empty box first.
Content Security Policy constraints. Occasionally a policy forbids external image sources, and inlining is the only route — though note that data: URIs themselves have to be permitted explicitly.
Generated images. A chart or QR code produced in the browser exists only as a data URI; there is nothing to link to.
Outside these, link the file and let the cache do its job.
Frequently asked questions
Why is the Base64 string larger than the original file?
Base64 represents every 3 bytes of binary data as 4 text characters, so the encoded form is about 33% larger. That overhead is the price of making binary data safe to embed in text.
Is there a size limit?
No hard limit, but data URIs over a few hundred kilobytes cause real problems: slower parsing, bloated HTML or CSS, and no separate caching. Keep inlined images small.
Do data URIs work in email?
Inconsistently. Gmail strips them, and several desktop clients block them. For email, host the image and link to it, or use a CID attachment.
Can I decode a data URI back to an image?
Yes — paste the Base64 portion into any Base64 decoder, or simply paste the whole data URI into your browser's address bar to view the image.