Inlining an Image Without Slowing the Page
By toolbelt maintainers ·
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?
Why can I not see the preview?
Which formats are detected?
Is this good for performance?
Related tools
- SVG OptimizerStrip comments, metadata and editor namespaces from an SVG and collapse redundant whitespace. Shows exactly how many bytes were saved.
- JSON ValidatorValidate JSON syntax with detailed error messages. Catch trailing commas, missing brackets, and syntax errors instantly before sending payloads to your API.
- JSON FormatterBeautify, validate, minify, and view JSON. Format messy API responses into readable code or compress it to save bandwidth, running safely in your browser.
- JSON MinifierCompress JSON to a single line. Remove all unnecessary whitespace and line breaks to reduce payload size for production APIs without altering the underlying data.