Image to Base64
Convert any image to a Base64 data URI. Drag & drop or click to upload — nothing leaves your browser.
What is Base64 image encoding?
Base64 encodes every three binary bytes as four ASCII characters. A data URL prefixes that with a MIME type so an <img> or CSS url() can paint the image without another request. FileReader.readAsDataURL is the browser API that performs both steps for a local File. See the MDN Data URLs.
The Image Input zone accepts one file: PNG, JPG, JPEG, GIF, WebP, or SVG, maximum 5 MB (react-dropzone maxSize). Drop or click Choose File. FileReader.readAsDataURL produces data:{mime};base64,{payload} using the browser’s MIME for that file. The same string is shown in Base64 Output and as a preview. Copy Base64 copies it. The sidebar Size is the character length of that URI in KB (length/1024), which is larger than the original file because Base64 expands binary by about 33% and the data: prefix adds a few dozen characters. Clear removes file, preview, and URI. There is no server upload. Data URLs skip an extra HTTP request but are not cached as separate assets and bloat HTML — keep them for small icons. To preview a URI you already have, use Base64 to Image (that page requires the data:image prefix this encoder emits).
When to use this tool
- Inline a small icon — A 1–2 KB PNG as an img src avoids a round trip on a static page or an email that blocks external images.
- CSS background — background-image: url("data:image/png;base64,…") for a repeating pattern that should travel with the stylesheet.
- JSON payloads — Some APIs accept a data URI string. Pretty-print the JSON in JSON Formatter after you paste. JSON Formatter
- Stay under 5 MB — Dropzone rejects files over 5 MB. Compress first in Image Resizer if you are over the cap. Image Resizer
- When embedding is worth it — Caching, size, and email caveats are covered in the encoding guide. Image to Base64 encoding guide
How to use the Image to Base64
Drop or choose a file
PNG, JPG, GIF, WebP, or SVG. One file. Max 5 MB. The zone shows the filename after a successful read.
Copy the data URI
Base64 Output is the full data:image/…;base64,… string. Copy Base64 copies it. The sidebar Size is URI length in KB, not original file size.
Use or reverse
Paste into HTML, CSS, or JSON. To see a URI as pixels again, open Base64 to Image — keep the prefix.
Worked examples
What FileReader emits for a 1×1 PNG
1×1 PNG file dropped on Image Input (under 5 MB)
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==
MIME comes from the file type. A JPEG drop starts with data:image/jpeg;base64,.
Oversize file
A 6 MB photograph
Dropzone rejects the file (maxSize 5 MB). Compress with Image Resizer, then drop again.
Tips
- Best for icons and patterns under ~10 KB of binary.
- The preview uses the same data URI as the textarea.
- Image to Base64 does not strip EXIF; the encoded bytes are the file you dropped.
Frequently Asked Questions
Is my image sent to a server?
No. FileReader.readAsDataURL runs in the browser. The file never leaves the device.
How do I use the output in CSS?
background-image: url("data:image/png;base64,…") or <img src="data:…">. Keep the quotes around the url() argument.
Why is the output longer than the file?
Base64 uses 4 characters per 3 bytes (~33% more), plus the data: prefix. The sidebar Size is that URI’s character length in KB.
Can I convert SVG files?
Yes. SVG is accepted and encoded like raster, producing data:image/svg+xml;base64,…. URL-encoding the SVG text can be smaller; this page always Base64-encodes the file bytes.
What is the size limit?
5 MB per file in the dropzone. Data URLs of any length can still slow a page; prefer them for small assets.