Image to Base64
Convert images to Base64 data URIs for embedding directly in HTML or CSS. Processed entirely in your browser — images are never uploaded.
Drop an image here, or click to browse
PNG, JPEG, GIF, WebP, SVG — max 5 MB
About the Image to Base64 Converter
Base64 encoding converts binary data — such as an image file — into a string of printable ASCII characters. The resulting string can be embedded directly in HTML, CSS, or JSON without referencing an external file. This is commonly used for small icons in CSS files, for email attachments, and for passing images through APIs that only accept text.
How to use a Base64 image in HTML and CSS
- HTML img tag —
<img src="data:image/png;base64,iVBOR..."> - CSS background —
background-image: url("data:image/svg+xml;base64,PHN2...") - Inline SVG — encode an SVG file to avoid CORS issues when loading from another domain
When should you avoid Base64?
Base64 increases file size by approximately 33% because it uses 4 characters to represent every 3 bytes. For images above 5KB, a standard <img> tag pointing to an external URL is better — browsers cache external image files, while Base64 strings embedded in HTML or CSS cannot be cached separately.
Data URIs vs external image files
The decision to use Base64-encoded data URIs versus external image files is a performance trade-off. Data URIs eliminate an HTTP request (good for small images), but increase HTML/CSS file size, cannot be cached separately, and increase page parse time. For large images or icons used across many pages, a sprite sheet or CDN-hosted SVG file is more efficient.
- Use data URIs for — small icons (<5KB), single-use images, email templates, offline apps
- Avoid for — large images, images reused across many pages (cannot be cached), background patterns
- SVG consideration — SVGs can be inlined directly in HTML (<svg>) rather than Base64-encoded, saving overhead
- HTTP/2 effect — multiplexed connections reduce the penalty of multiple HTTP requests, making data URIs less necessary on modern stacks
Frequently Asked Questions
background-image: url("data:image/png;base64,..."). This is useful for small icons in CSS frameworks or email templates where external file references may be blocked.url("data:image/svg+xml,%3Csvg..."), which produces a slightly smaller result and stays human-readable.import base64; open("out.png","wb").write(base64.b64decode(data)).