Image

When to Use Base64 Images (and When Not To)

ToolOrbit Team 2 min readUpdated
When to Use Base64 Images (and When Not To)

Base64 image encoding converts binary image files (PNG, JPG, SVG, WebP) into plain-text data URLs. This allows you to embed images directly inside HTML, CSS, or JSON without requiring an external HTTP request.

Code Examples: How to use Base64 images

1. In HTML <img> tags

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." alt="Embedded icon" width="32" height="32" />

2. In CSS stylesheets (Background images)

.badge {
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0...");
  background-repeat: no-repeat;
}

3. In JavaScript with FileReader API

function fileToBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
    reader.readAsDataURL(file);
  });
}

When should you use Base64 images?

  • Small UI icons and favicons (under 10KB) to reduce round-trip HTTP requests.
  • HTML email templates where external images are frequently blocked by email clients.
  • Offline web applications and single-file HTML distributions.
Convert any image to Base64 in 1-click with our free Image to Base64 tool — 100% private in your browser.

The performance trade-off, honestly

Base64 inflates binary by about 33 percent, keeps the browser from caching the image separately, and forces the whole blob through the HTML document. Inline Base64 is a reasonable choice for tiny, never-changing assets (a logo or a 1×1 spacer below a few KB) and for images delivered straight from a database. It is the wrong tool for a 2 MB photo: the page HTML alone becomes large enough to slow first render.

  • Use inline Base64 under ~10 KB and where the asset never varies.
  • Keep real files as <img src> URLs so browsers can cache them.
  • If a base64 image must be large, lazy-load it like any other resource.
Inline the CSS/HTML path here produces markup you can paste directly — ideal for email signatures, where external images are often blocked by default.

For images the page needs immediately but cannot cache — embeds, attachments, and email signatures — this approach is not lazy: it trades bytes for guaranteed availability. The bigger the embed, the larger the tax: 750 KB in, roughly 1 MB out. Applying it to a 30 KB logo costs nothing; to a 3 MB photo, everything.

Data URIs in CSS are legal everywhere when quoted carefully. Prefer PNG/JPG/WebP data here; SVG-as-data is strictly for the brave.

Frequently asked questions

Place the data URL directly in the src attribute of an <img> tag: <img src="data:image/png;base64,iVBORw..." alt="Icon" />

Use it in the url() property: .icon { background-image: url("data:image/png;base64,iVBORw..."); }

Use the FileReader API: const reader = new FileReader(); reader.onload = () => console.log(reader.result); reader.readAsDataURL(file);

Yes. Base64 encoding increases file size by approximately 33%. It is best used for small icons and thumbnails under 10KB.


Tools mentioned

More reading

View all guides
Crop vs Resize vs Compress: What Cropping Does to an Image
Image

Crop vs Resize vs Compress: What Cropping Does to an Image

What cropping changes, how it affects file size, and how it differs from resizing and compressing.

2 min readUpdated
PNG vs JPG vs WebP: Which Image Format Should You Use?
Image

PNG vs JPG vs WebP: Which Image Format Should You Use?

When to pick PNG, JPG or WebP, what lossy and lossless really mean, and how to convert without throwing away quality.

2 min readUpdated
Why Rotating an Image by 90 Degrees Loses No Quality
Image

Why Rotating an Image by 90 Degrees Loses No Quality

Why right-angle rotation is lossless, how it differs from rotating by an arbitrary angle, and how EXIF orientation causes sideways photos.

2 min readUpdated
How Image Filters Work: Grayscale, Sepia, Contrast and Blur
Image

How Image Filters Work: Grayscale, Sepia, Contrast and Blur

What each image adjustment does, the order that gives the cleanest result, and three looks you can build from the sliders.

2 min readUpdated
Favicon Sizes: Which Ones You Need and How to Add Them
Image

Favicon Sizes: Which Ones You Need and How to Add Them

Which favicon sizes browsers, iPhones and Android actually use, how to turn a logo into a clear 16px icon, and how to test it before launch.

2 min readUpdated
How to Pick a Color from an Image (Copy HEX & RGB Codes)
Image

How to Pick a Color from an Image (Copy HEX & RGB Codes)

Pick exact HEX, RGB, and HSL color codes from any image. Extract dominant color palettes and copy color codes in 1 click.

2 min readUpdated
Your Photos Know Where You Live: How to Remove EXIF Data
Image

Your Photos Know Where You Live: How to Remove EXIF Data

Every phone photo embeds GPS coordinates, device details and timestamps. Here is what EXIF data reveals, who strips it for you, and how to remove it yourself.

3 min readUpdated
The Complete Guide to Image Optimization
Image

The Complete Guide to Image Optimization

Choose the right format, compress without visible loss, and serve responsive images that keep your pages fast.

2 min readUpdated