Image to Base64 Converter
Convert images to Base64 data URLs (for embedding in HTML/CSS), or decode a data URL to preview the image.
What is a data URL?
A data URL embeds a file directly inside a document rather than referencing it by address. Instead of pointing at logo.png, you include the image itself as Base64 text within the HTML or CSS.
data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
The benefit is one fewer HTTP request. The cost is a 33% size increase, no independent caching, and a larger render-blocking document. Whether that trade is worth it depends almost entirely on the size of the image.
Key takeaways
- Base64 encoding makes a file about 33% larger.
- Data URLs save an HTTP request but cannot be cached separately.
- Only worth it for very small images - a few kilobytes at most.
- Inline SVG is almost always better than a Base64-encoded SVG.
- Never inline large images; it delays rendering of the whole document.
When to inline and when not to
| Image | Typical size | Inline? | Why |
|---|---|---|---|
| Tiny icon | Under 1 KB | Yes | Request overhead exceeds the file |
| Small logo | 1-5 KB | Maybe | Depends how often it changes |
| UI sprite | 5-20 KB | Rarely | Better cached separately |
| Photograph | 50 KB+ | No | Blocks rendering, cannot be cached |
| Hero image | 200 KB+ | Never | Seriously damages performance |
| SVG icon | Any | Inline as SVG | Smaller than Base64 and styleable with CSS |
The caching problem
This is the argument that settles most cases. A referenced image is a separate resource with its own cache entry: downloaded once, reused across every page for as long as the cache header allows.
An inlined image has no separate identity. It is part of the stylesheet or the HTML document, so:
- It is re-downloaded whenever that document changes, even though the image did not.
- It cannot be served from a CDN edge independently.
- It inflates every HTML response if inlined in markup rather than CSS.
- Changing one inlined image invalidates the cache for the whole stylesheet.
Using data URLs in code
In CSS
background-image: url("data:image/png;base64,iVBOR...");
}
In HTML
Both work in every browser. Note that data URLs in CSS are affected by Content Security Policy - a strict img-src directive may need data: added explicitly.
Image format selection
| Format | Best for | Transparency | Notes |
|---|---|---|---|
| SVG | Icons, logos, line art | Yes | Scales infinitely; inline it directly |
| PNG | Screenshots, sharp edges, transparency | Yes | Lossless and often large |
| JPEG | Photographs | No | Lossy; adjust quality to taste |
| WebP | Almost everything | Yes | Roughly 25-35% smaller than JPEG |
| AVIF | Photographs | Yes | Smaller still; slower to encode |
Optimize the image before encoding. Base64 preserves whatever you give it, so encoding an unoptimized 500 KB PNG produces 665 KB of text.
Frequently Asked Questions
What is a Base64 data URL?
A way of embedding a file directly in a document rather than linking to it. The image is encoded as Base64 text and included inline, so the browser does not need a separate request to fetch it.
How much larger does Base64 make an image?
About 33 percent, because three bytes of binary data become four text characters. A 30 KB image becomes roughly 40 KB of Base64 text.
When should I use a data URL?
Only for very small images - typically under a few kilobytes - where the overhead of a separate request outweighs the size penalty. For anything larger, a referenced file that can be cached independently is better.
Should I Base64-encode SVG files?
No. SVG is already text, so Base64 makes it 33 percent larger for no benefit. Inline the SVG markup directly instead - it is smaller and can be styled and animated with CSS, which a data URL prevents.
Why is caching a problem with data URLs?
Because an inlined image has no separate cache entry. It is part of the stylesheet or HTML, so it is re-downloaded whenever that file changes, cannot be served independently from a CDN, and changing one image invalidates the cache for the whole document.
Did HTTP/2 change the case for inlining?
Yes, substantially. The original argument rested on request overhead, which was significant when browsers limited connections per host. HTTP/2 multiplexes many requests over one connection, making an extra request much cheaper, while the caching penalty of inlining is unchanged.
Do data URLs work in every browser?
Yes, in both CSS backgrounds and img elements. One thing to watch is Content Security Policy - a strict img-src directive may need data: added explicitly for inline images to load.
Are my images uploaded when I convert them?
No. Encoding happens entirely in your browser using the FileReader API. The image never leaves your device.