Blog
Wild & Free Tools

Base64 Images in HTML and CSS — How Data URIs Work

Last updated: January 15, 2026 6 min read

Table of Contents

  1. What Is a Base64 Data URI?
  2. Using Base64 Images in HTML
  3. Using Base64 Images in CSS
  4. When to Use (and When to Avoid) Base64 Images
  5. How to Decode a Base64 Image String
  6. Base64 Images in HTML Emails
  7. Frequently Asked Questions

If you have ever inspected the source code of a web page and seen a 500-character string starting with data:image/png;base64,iVBORw... inside an <img> tag, you have encountered a Base64 data URI. It is one of the most common but least understood uses of Base64 encoding on the web.

This guide explains what data URIs are, how they work in HTML and CSS, when embedding images this way makes sense, and how to inspect or decode a Base64 image string using a free browser tool — no software required.

What Is a Base64 Data URI?

A data URI (Uniform Resource Identifier) is a way to embed file content directly into a document, instead of linking to an external file. The format is:

data:[mediatype];base64,[base64-encoded-data]

For an image, this looks like:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...

The browser reads this string and renders it as an image — no HTTP request needed. The image is encoded directly in the page source.

The mediatype tells the browser what kind of file it is (image/png, image/jpeg, image/gif, image/svg+xml). The base64 keyword signals that what follows is Base64-encoded binary data. The actual content after the comma is the entire image file, converted to text characters.

Using Base64 Images in HTML

You can use a Base64 data URI anywhere an <img> tag accepts a src attribute:

<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">

This works in every modern browser. The browser decodes the Base64 string back into binary image data and displays it exactly like a normally-hosted image.

The main advantage is that the image loads with zero additional HTTP requests. For very small images — icons, decorative elements, tiny logos — this can reduce page load time by eliminating round-trip latency. A 2KB icon hosted externally might add 50–200ms of latency depending on the server. Embedded as Base64, it loads instantly with the HTML.

The tradeoff: the Base64 string is roughly 33% larger than the original binary file. A 3KB PNG becomes about 4KB of Base64 text. For small images this is acceptable. For large images, it is not.

Using Base64 Images in CSS

You can also embed images directly in CSS using the background-image property:

.icon {
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxu...");
  background-size: contain;
  width: 24px;
  height: 24px;
}

This is especially common with SVG icons, since SVG files are XML text to begin with and encode very efficiently in Base64. Some developers even inline SVG directly (without Base64) using url("data:image/svg+xml,<svg...>"), but Base64 is more reliably cross-browser.

CSS data URIs shine in component libraries and design systems where you want zero external dependencies — the icon is baked into the stylesheet. Any developer who installs the CSS gets the icons automatically, with no separate asset folder to manage.

Sell Custom Apparel — We Handle Printing & Free Shipping

When to Use (and When to Avoid) Base64 Images

Use Base64 images when:

Avoid Base64 images when:

How to Decode a Base64 Image String

If you have a Base64 image string and want to inspect the raw data, or verify what the encoded content actually is, you can paste the Base64 portion (everything after the comma) into our free Base64 Encoder/Decoder tool and decode it. The result will be the raw binary content as text characters.

Note: the decoded output will look like garbled binary text in a browser text area — that is expected. Binary image data is not human-readable text. What you are verifying is that the string decodes without errors and produces output of the expected length.

To convert an image to Base64 in the first place, you typically need a tool that reads binary files — a server-side script, a command line tool, or a dedicated image-to-Base64 converter. Our encoder handles text strings and is the right tool for decoding and inspecting Base64 image strings, encoding textual content for APIs, and testing data URIs you have already assembled.

Base64 Images in HTML Emails — The Exception to the Rule

HTML email is the one context where Base64 images are almost always worth it, regardless of size. Here is why: most email clients (Outlook, Apple Mail, Gmail with image blocking enabled) will not load external images by default. The reader sees a broken image placeholder until they click "load images." Base64-embedded images always show because they are part of the email itself — no external request needed.

Email marketing platforms like Mailchimp and Klaviyo typically host images on their CDN and use external links, relying on recipients clicking "show images." For transactional emails where you absolutely need an image to display (a QR code, a ticket, a signature logo), Base64 embedding is the safer choice.

The size penalty matters less for email. A 300KB email is normal. The certainty of display is worth the tradeoff when the image is essential to the message.

Try It Free — No Signup Required

Runs 100% in your browser. No data is collected, stored, or sent anywhere.

Open Free Base64 Encoder/Decoder

Frequently Asked Questions

Can I use a Base64 string directly in an img src attribute?

Yes. Set src="data:image/png;base64,[your-encoded-string]" and the browser renders it as a normal image. Replace "png" with the actual format of your image (jpeg, gif, svg+xml, etc.).

How do I convert an image to Base64?

You need a tool that reads binary files. Command-line tools (Linux/Mac: base64 -i image.png), online image-to-Base64 converters, or server-side code in Python (base64.b64encode) or JavaScript (FileReader.readAsDataURL) all work. Our text encoder handles text strings and is useful for decoding and inspecting existing Base64 image data.

Why is my Base64 image string so long?

Base64 encoding increases file size by about 33% because it converts binary bytes into printable ASCII characters. A 100KB image produces roughly 133KB of Base64 text. This is normal and expected.

Do Base64 images affect SEO?

Not directly. Search engines can index page content regardless of how images are loaded. However, very large inline Base64 images can slow page load times, which does affect Core Web Vitals and indirectly affects SEO rankings.

Jake Morrison
Jake Morrison Security & Systems Engineer

Jake has spent a decade on client-side security architecture. His conviction that files should never touch a third-party server is the foundation of WildandFree's zero-upload design.

More articles by Jake →
Launch Your Own Clothing Brand — No Inventory, No Risk