Skip to content
toolbelt
Back to Guides

Inlining an Image Without Slowing the Page

By ·

Updated

A data URI removes a request and adds 33 percent to the bytes. On a small icon that is a win. On a photo it is a mistake.

What is this tool?

A data URI embeds an image in HTML or CSS as base64 text, so there is no separate file to fetch.

How it works

Base64 turns three bytes into four characters, which is where the 33 percent comes from. I decode the string, read the first bytes to identify the format from its signature rather than trusting a label, and rebuild a normalised URI.

Example

data:image/png;base64,iVBORw0KGgoAAAANSUhEUg

data:   the scheme
image/png: the media type
base64:  the encoding of what follows

When to use it

Icons under about 2KB. A placeholder used once. Email templates, where external images are often blocked by default.

Optimization Tips

Inline only what is small and used once. A data URI cannot be cached separately, so putting one in a shared stylesheet means it downloads again on every page. And prefer SVG for icons — it compresses far better than a base64 bitmap.

Frequently Asked Questions

Does base64 hide the image?
No. It is an encoding. Anyone can decode it instantly.
Why can I not see the preview?
Usually a truncated string or missing padding. The length must be a multiple of four.
Which formats are detected?
PNG, JPEG, GIF, WebP, BMP and ICO, identified from the file signature.
Is this good for performance?
Only for small, single-use assets. For anything else, a cached file is faster overall.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools