Inlining an image as a data URI (data:image/png;base64,...) saves an HTTP request. It also makes the image about 33% bigger, because Base64 turns every 3 bytes into 4 characters. Whether that's a good trade depends on the image.

When inlining is reasonable

  • Tiny icons and UI bits (a few hundred bytes to ~2 KB) that would otherwise be separate requests.
  • Single-file deliverables: an HTML email template, an offline report, a demo in one file.
  • Images in JSON APIs that are documented as "base64-encoded".

When it hurts

  • Anything big. A 200 KB photo becomes ~267 KB of text inside your CSS or HTML, which blocks rendering and can't be cached separately.
  • Images used on many pages. A normal file is downloaded once and cached; an inlined copy is re-downloaded with every stylesheet or page that contains it.
  • Images that change often: every change invalidates the whole CSS file.

SVG is a special case

For SVG, URL-encoding (data:image/svg+xml,%3Csvg...) is usually shorter than Base64, because SVG is already text.

Quick checklist

  1. Under ~2 KB and used in one place? Inline is fine.
  2. Bigger, or reused? Keep it a file and let the cache do its job.
  3. With HTTP/2 and HTTP/3, the "save a request" benefit is smaller than it used to be, so lean towards files.

Disclosure: I run GoToolsOnline. If you need to convert, its image-to-Base64 tool runs in your browser, shows how much bigger the Base64 is in percent, and outputs a data URI, raw Base64, a CSS rule, an img tag, Markdown or JSON: https://gotoolsonline.com/tools/image-base64