RunToolz iconRunToolz
Welcome to RunToolz!
Base64ImagesPerformance

Base64 Images: Convenient Trap or Useful Tool?

Embedding images as Base64 strings seems convenient. Here's when it helps and when it hurts.

RunToolz TeamJanuary 10, 20263 min read

You can embed an image directly in HTML or CSS. No separate file. No extra HTTP request.

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

Convenient. But it comes with costs that aren't immediately obvious.

How It Works

Base64 encodes binary data as ASCII text. Any image becomes a string you can copy and paste.

The string is about 33% larger than the original file. A 30KB image becomes a 40KB string.

Ready to try it yourself?Convert Image to Base64

When Base64 Helps

Tiny icons. A 200-byte icon as Base64 saves an HTTP request. HTTP/2 made this less important, but it's still valid for very small images.

Email HTML. Email clients block external images. Embedded images display without that "load images" prompt.

Single-file distribution. Sharing HTML that works offline. Everything in one file.

Data URIs in CSS. Background images embedded in stylesheets. Reduces HTTP requests at the cost of larger CSS files.

When Base64 Hurts

Large images. The 33% size increase adds up. A 100KB image becomes 133KB of text.

Caching. External images cache separately. Base64 images are part of the HTML/CSS—if the page changes, the entire thing reloads.

Parse time. Browsers must decode Base64 before rendering. More processing than loading a binary file directly.

Maintenance. Updating an embedded image means editing code. Updating an external file is simpler.

The HTTP/2 Factor

HTTP/1.1 had expensive connection overhead. Multiple small images meant multiple slow requests.

HTTP/2 multiplexes requests efficiently. The "save HTTP requests" argument is weaker now.

If your server supports HTTP/2 (most do), external images are usually better.

Practical Guidelines

Under 1KB: Consider Base64. The overhead is minimal.

1-10KB: Evaluate case by case. Critical icons might benefit, decorative images probably don't.

Over 10KB: Use external files. The size penalty isn't worth it.

Frequently updated: External files. Avoid changing code for image updates.

Shared across pages: External files. Caching benefits multiple page loads.

Performance Testing

Don't guess. Test.

Compare total page weight with and without Base64 embedding. Measure actual load times.

The "right" answer depends on your specific situation—image sizes, caching strategy, HTTP version, update frequency.

Alternatives

Sprite sheets. Combine small icons into one image, use CSS to display portions. One request, normal caching.

Icon fonts. Vector icons as fonts. Scalable, styleable with CSS.

SVG inline. For vector graphics, inline SVG offers more flexibility than Base64 PNG.


Base64 images trade file size for convenience. That trade-off only makes sense for very small images or special cases like email. For most web use, external files perform better.