Image to Base64 Encoder — Embed Images in CSS, HTML, JSON
Convert images to base64 data URIs for inline embedding in CSS, HTML, JSON, or markdown. Bidirectional — also decodes base64 back to image.
About Image to Base64
A base64 image encoder converts a binary image (JPG, PNG, WebP, GIF, SVG) into a base64-encoded data URI string of the form `data:image/png;base64,iVBORw0KG...`. The ZTools Image Base64 tool encodes any image up to ~10 MB into a copy-pasteable data URI suitable for inline CSS `background: url(data:...)`, HTML `<img src="data:...">`, JSON payloads, markdown documents, or anywhere else you need an image without a separate file. Bidirectional: also decodes a data URI back into a previewable, downloadable image.
Use cases
- Inlining a small icon or logo in CSS. Embedding a 1-2 KB icon as a base64 background URL eliminates a separate HTTP request. For icons used on the critical render path (hero logo, hamburger button), this can shave 50-100 ms off the first meaningful paint on slow connections.
- Sending an image inside a JSON API payload. Some APIs (especially older ones or those without multipart support) require image data inside a JSON string field. Convert the image to base64 here, paste into the JSON, and send. The receiving server decodes back to bytes server-side.
- Embedding images in self-contained HTML emails or reports. Email clients block external image references by default. Inline base64 images render immediately without the "Download images" prompt. Useful for reports, signatures, and transactional emails.
- Including images in markdown documentation that renders without external assets. For README files distributed standalone or rendered in environments without internet access, base64-embedded images keep the document self-contained. Adds size but eliminates broken-link risk.
How it works
- Drag-drop or select an image. JPG, PNG, WebP, GIF, SVG, BMP, ICO supported. Files up to ~10 MB encode comfortably; larger files produce data URIs too long for most practical uses.
- The browser reads the file as binary. A `FileReader.readAsArrayBuffer()` loads the image into memory; never sent to a server.
- Bytes are base64-encoded. The native `btoa()` (with binary-safe wrapping) produces the encoded string. The MIME type is auto-detected from the file extension and prepended.
- Output as a complete data URI. Format: `data:image/png;base64,iVBORw0KG...`. Ready to paste into CSS, HTML, JSON, or markdown.
- Copy with one click. For decoding, paste a data URI; the tool reverses the operation and shows a preview plus download.
Examples
Input: 64×64 PNG logo (3.2 KB)
Output: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAAC...
Encoded length: ~4.3 KB (base64 adds ~33% overhead). Suitable for inline CSS background.
Input: data:image/svg+xml;base64,PHN2Zy...
Output: <previewable, downloadable SVG image>
Reverse direction: paste data URI, get image back.
Frequently asked questions
When should I inline an image as base64 vs. link to a file?
Inline only for images under ~5 KB or those on the critical render path. Above ~5 KB, the bandwidth and parse cost outweighs the saved HTTP request — especially with HTTP/2 multiplexing.
How much larger does an image get when base64-encoded?
Approximately 33% larger (every 3 bytes of binary become 4 base64 characters), plus the `data:image/PNG;base64,` prefix. After gzip, the inflation drops to ~5-10%.
Will inlining hurt browser caching?
Yes — inlined images cannot be cached separately from the document. For images reused across pages, prefer a real file with strong cache headers.
Can I decode a base64 string back to a downloadable image?
Yes — paste a complete data URI (with the `data:image/...;base64,` prefix or just the base64 payload), and the tool decodes and previews it. One-click download.
Is the base64 encoding the same as encryption?
No — base64 is encoding, not encryption. Anyone can decode it back to the original bytes trivially. Never use base64 to "hide" sensitive image content.
Does it work offline?
Yes. Once the page loads, encoding and decoding work without internet. Test by disconnecting and converting an image.
Pro tips
- Use base64 inlining only for images under 5 KB; above that, file-based references with caching win.
- For SVG images, prefer inlining the SVG markup directly (smaller and CSS-styleable) rather than base64-encoding it.
- When inlining in CSS, prefer external font-icons or SVG sprites for icon sets — better caching and theming.
- Combine with our Image Compressor to minimize the source file before encoding.
Reviewed by Ahsan Mahmood · Last updated 2026-05-05 · Part of ZTools.
For the full,
formatted version of this page, please enable JavaScript and reload
https://ztools.zaions.com/image-base64.