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
| File | Mime type | Notes |
|---|---|---|
| PNG | image/png | Lossless, supports transparency |
| JPEG | image/jpeg | No transparency |
| WebP | image/webp | Small, supported by modern browsers |
| SVG | image/svg+xml | Can also be inlined as text |
| GIF | image/gif | Animated |