Free · processed in your browser · account only to save the .txt
Convert an Image to Base64
Drop a PNG, JPG, WebP, GIF, SVG or AVIF file (up to 10 MB) to get its exact Base64 string, data URL, CSS background rule and HTML img snippet. Your file is read on your device and is not uploaded.
How do I convert an image to a Base64 string or data URL?
Drop a PNG, JPG, WebP, GIF, SVG or AVIF file under 10 MB into the box above. The browser reads the raw file bytes without re-encoding the image and builds four copyable blocks: the full `data:image/...;base64,...` URL, the raw Base64 payload, a CSS `background-image` rule, and an HTML `<img>` tag, plus a downloadable `.txt` file.
How it works
01
Add your image
Drag one PNG, JPG, WebP, GIF, SVG or AVIF file into the box, up to 10 MB. Dropping another file replaces the current result.
02
Pick the snippet you need
The page shows all four blocks: Data URL, Raw Base64, CSS and HTML. Long strings are trimmed to 4,000 characters inside the preview boxes so the page stays fast, while the Copy buttons copy the complete string.
03
Copy or download as text
Press Copy under any block to copy the full output to your clipboard, or click Download to save all four snippets in one `-base64.txt` file. Copying needs no account; saving the file needs a free HeyDreaming account.
Byte-exact encoding and MIME detection
Unlike a canvas converter, this tool reads your file's exact binary bytes and encodes them directly to standard Base64. Nothing is redrawn, resized or re-compressed: animated GIFs, vector SVGs, transparency and embedded metadata stay byte-for-byte identical to the file on your disk, and decoding the output in Base64 to Image restores the exact original file.
To build the `data:<mime>;base64,...` prefix, the tool inspects the file header bytes first (recognizing PNG, JPEG, GIF, WebP, AVIF, BMP and SVG signatures) and falls back to the browser's reported file type if needed.
Why Base64 text is about 33% larger than the file
Base64 represents every 3 bytes of binary data as 4 ASCII characters, which increases the byte size by roughly one third. The result row shows both your original file size and the resulting Base64 text size so you can judge whether inlining makes sense. Files up to 10 MB are accepted and encoded in small async chunks so the browser tab stays responsive.
Inline Base64 works well for small icons, single-file HTML exports, email templates and CSS sprites where saving a separate network request matters more than the 33% size overhead. For large photographs on a webpage, serving a regular WebP, AVIF or JPG file is almost always faster.
What this tool does not do
It does not compress or resize the image before encoding (use Image Compressor first if your Base64 string is too long), convert HEIC files, or encode multiple files at once.
Keep exploring
Related free tools
Questions
Image to Base64: FAQ
Is my image uploaded when I encode it to Base64?
No. The file is read and encoded inside your browser, so your image stays on your device. The page sends usage events to Google Analytics, such as which tool ran, but never the file or Base64 text.
Why does the text box say my Base64 was cut off at 4,000 characters?
Rendering millions of characters inside four `<textarea>` elements at once can freeze a browser tab. Only the on-screen preview box is truncated to 4,000 characters; clicking Copy or downloading the `.txt` file gives you every character.
What is the difference between a Data URL and Raw Base64?
Raw Base64 is just the encoded characters (`iVBORw0KGgo...`), which APIs and JSON payloads often expect. A Data URL adds the `data:image/png;base64,` header in front so browsers can use it directly in an `<img src>` or CSS `url()`.
Does encoding change image quality or strip metadata?
No. The encoder reads the file's raw bytes without touching a canvas, so every byte—including quality, color profile, animation frames and EXIF data—is preserved intact.
How can I make the Base64 output shorter?
Because Base64 length is directly proportional to the input file's byte size, run the image through Image Compressor or Image Resizer first, then drop the smaller file here.