Base64 images: when inlining helps, when it hurts
Data URIs save one request but add about 33% to the payload. A short guide to choosing.
2026-11-29
What a data URI really is
A base64 image is the file's bytes encoded as text and pasted into HTML or CSS: data:image/png;base64,…. The browser decodes it like a normal image, with no second request. The cost is size: base64 is roughly a third larger than the binary, and the whole string sits in the document.
That trade — one request less, more bytes — is the entire decision. The rest is about which side wins for a given image.
Where it wins
Icons under a couple of kilobytes, a logo in a single-file HTML demo, a tiny texture in CSS, or an export pipeline that must produce one self-contained file. Small SVG data URIs in CSS also make sense where an extra request would block rendering.
In email signatures it is tempting, but many clients block data URIs. A hosted image is still more reliable there.
Where it hurts
A 200 KB photo becomes about 270 KB of text, cannot be cached separately, and is downloaded again with the HTML on every visit. It also delays first paint, because the parser has to read the string before reaching the content below.
Large inline images are especially bad on mobile plans and on pages that repeat the same image across many URLs. A normal file is cached once and reused; inline copies cannot be shared.
A rule that works
Under 2 KB, inline it. Above 10 KB, use a file. In between, look at reuse: if the asset appears on every page, a cached file wins; if it appears once in a downloadable document, inline is fine.
For icons that must scale, prefer SVG. It is already text and often smaller than the base64 PNG it replaces. For photos, never inline.