Performance

Base64 images: when to inline them (and when not to)

Base64 data URIs save a request but cost caching, lazy loading and render speed. Measured sizes, the cases where inlining helps, and why SVG should be URL-encoded instead.

Use Base64 images only for very small files, roughly under 10 KB: icons, a tiny logo, a blurred placeholder, or images in HTML email. Base64 text is about 33% larger than the original file, it can’t be cached separately from the CSS or HTML it sits in, and a large data URI in a stylesheet delays rendering until the whole stylesheet has downloaded. For anything bigger, a normal image file with good caching is faster.

Key takeaways

  • Base64 turns every 3 bytes into 4 characters, so the encoded text is about a third bigger.
  • Gzip and Brotli win most of that back in transfer, but not the caching and render-blocking costs.
  • Good uses: tiny icons, placeholders, email, single-file demos. Bad uses: photos, hero images, anything reused across pages.
  • SVG doesn’t need Base64 at all; URL-encoding it is shorter.

What is a Base64 image?

Base64 writes binary data using only 64 safe characters: A–Z, a–z, 0–9, plus and slash. Wrapped in a data URI, an entire image can live inside your HTML or CSS as text:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA…" alt="">

.icon {
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA…");
}

The browser decodes the text back into the image without making a separate request for it. You’ll find data URIs in plenty of themes, plugins and email templates, often added automatically by build tools that inline anything below a size threshold. That saving was a big deal when every HTTP request was expensive. With HTTP/2 and HTTP/3 sending many files over one connection, it matters far less.

How much bigger does Base64 make an image?

Every 3 bytes of the file become 4 characters, so the encoded text is about 4/3 the size of the original. Compression on the server (gzip or Brotli) claws much of that back, because Base64 text is very repetitive in its use of characters. I measured two images in the browser:

ImageOriginal fileBase64 textBase64, gzipped
32×32 PNG icon559 bytes748 bytes602 bytes
1600×900 JPEG92,872 bytes123,832 bytes85,364 bytes

So over the network, a Base64 image inside a gzipped stylesheet costs about the same bytes as the file itself. The size penalty isn’t really the problem. These are:

  • No separate caching. An image file is cached once and reused on every page. Inlined, it is downloaded again inside every HTML page, or the whole stylesheet has to be re-downloaded whenever any rule changes.
  • Render blocking. CSS blocks rendering until it has fully downloaded. A 100 KB image inside it holds up the whole page, even if that image is below the fold.
  • No lazy loading or responsive sizes. You lose loading="lazy", srcset and format negotiation, so phones download the same image as desktops.
  • Decoding cost. The browser has to parse the long string and decode it before it can show the image.

When should you use Base64 images?

Use it forAvoid it for
Tiny icons (a few hundred bytes to a few KB)Photos and hero images
Blurred image placeholdersImages used on many pages
HTML emails, where linked images are often blockedAnything over about 10 KB
Single-file demos and offline HTML pagesImages that need srcset or lazy loading
Favicons in a quick prototypeYour production favicon set

Placeholders are the best everyday use. A tiny blurred placeholder of a few hundred bytes, inlined as a data URI, can show instantly while the real image loads. See BlurHash vs LQIP and the blur placeholder generator.

Email: Email clients often block remote images until the reader allows them, and several popular clients, Gmail among them, don’t display data URI images reliably. Test in the clients your audience uses before relying on Base64 in email.

What about SVG?

SVG is already text, so encoding it in Base64 makes it bigger and unreadable for no benefit. URL-encode it instead: only a few characters, such as #, <, > and %, need escaping. The result is usually shorter than Base64 and compresses better. The SVG to CSS converter does that for you, and our guide to SVG data URIs in CSS explains the details.

How do you find Base64 images slowing a page down?

Open your browser’s developer tools and look at the size of your CSS and HTML files in the Network panel. A stylesheet that is hundreds of kilobytes for a modest site often has images or fonts inlined. Search the file for base64, to find them. Lighthouse also flags render-blocking stylesheets, and page builders and plugins are a common source: some inline icons, fonts or background images automatically. Moving a large inlined image back to a normal file, served at the right size with srcset and sizes, usually improves the first paint straight away.

How do you convert Base64 back to an image?

Paste the Base64 string or full data URI into the decoder side of the image to Base64 converter. It detects the format, previews the image and lets you download the file. This is handy when you find an image buried in someone else’s CSS, an API response or an email source.

Convert an image

Drop images into the image to Base64 converter and choose the output: a plain data URI, a CSS background rule, an HTML img tag, Markdown or the raw Base64. Everything runs in your browser. Before inlining anything, shrink it: compress photos with the compress to size tool and clean SVGs with the SVG optimiser.

Last checked: October 2026.

Sources: MDN: data: URLs, MDN: Base64, web.dev: Render-blocking resources.