What a data URI contains

A data URI has three parts: the mime type (image/png), the encoding marker (;base64), and the encoded bytes. For example: data:image/png;base64,iVBORw0KGgo.... Browsers render it exactly like a remote image, with no extra request.

When data URIs help

  • Tiny icons and logos that would otherwise add an HTTP request.
  • Single-file HTML demos that must work offline.
  • Email templates where external images may be blocked.
  • Test fixtures that need a deterministic image payload.

When they hurt

Base64 adds about 33% to the byte size, and data URIs are not cached separately by the browser. A 2 MB photo becomes a 2.7 MB string inside your HTML, blocking parsing and inflating the document. For anything larger than a few kilobytes, serve the image as a file and let the browser cache it.

Gzip does not compress Base64 well because the alphabet is already high-entropy. If size matters, optimize the image before encoding.

Mime types

FileMime typeNotes
PNGimage/pngLossless, supports transparency
JPEGimage/jpegNo transparency
WebPimage/webpSmall, supported by modern browsers
SVGimage/svg+xmlCan also be inlined as text
GIFimage/gifAnimated