Image to Base64
Encode an image file as Base64 text
Click or drop an image hereChoose an image
About Image to Base64
Image to Base64 reads an image file and writes its bytes as Base64 text, ready to paste into HTML, CSS, JavaScript, or a JSON payload. Any image type can be chosen (JPG, PNG, GIF, WebP, AVIF, SVG, BMP, ICO, TIFF, HEIC), because the file is not opened or re-compressed: the bytes your browser receives are encoded as they are, so the text is about a third larger than the file. The "Output" menu switches between a data URI, plain Base64, an HTML img tag, a CSS background-image rule, and JSON with the name and MIME type. Encoding starts as soon as you pick the file, in your browser.
Example
A 1 × 1 red PNG named red-dot.png (69 bytes) and the JSON form this tool writes for it, produced by the same steps as the page (FileReader data URI, then the "JSON" choice).
red-dot.png (bytes, hex)
89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 01 00 00 00 01 08 02 00 00 00 90 77 53 de 00 00 00 0c 49 44 41 54 78 9c 63 f8 cf c0 00 00 03 01 01 00 c9 fe 92 ef 00 00 00 00 49 45 4e 44 ae 42 60 82
Output: JSON
{"name":"red-dot.png","mime":"image/png","base64":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC"}How to convert an image to Base64
- 1Pick an image in the upload area; the Base64 text appears at once, with no convert button.
- 2Choose the form you need in the "Output" menu.
- 3Click "Copy Base64" to copy the text in that form.
- 4Or click "Download" to save the same text as a .base64.txt file.
Formats and limits
- Input
- Any image file: JPG, PNG, GIF, WebP, AVIF, SVG, BMP, ICO, TIFF, HEIC, and others
- Output forms
- Data URI, plain Base64, HTML img tag, CSS background-image, JSON; copy or .txt download
- Text box
- Shows the first 100,000 characters; copy and download give the full text
- Files at once
- One
Where your file is processed
The file is read with your browser's FileReader and encoded on this page; it is not uploaded, and the text exists only in this tab until you copy or save it. If the page shows an error, such as an empty file, that cleaned message is logged for us with the tool's name and your browser's name and version, without the file or its name.
Frequently asked questions
Can I get the Base64 string without the data: prefix?
Yes. Choose "Plain Base64" in the "Output" menu: the text then starts directly with the encoded bytes, which is what most APIs and JSON fields expect.
Is the image compressed or resized before encoding?
No. The bytes the page receives are encoded as they are. On an iPhone, a photo picked from the photo library can arrive already converted by iOS (HEIC becomes JPG); pick it through the Files app to encode the original file.
Can I encode HEIC or TIFF images?
Yes, the file is encoded byte for byte whatever its type. But a data URI only shows as a picture in a browser that can open that format: on a computer, Chrome, Edge, and Firefox do not display HEIC or TIFF.
Is the whole image in the text box?
No, not for large files. The box shows the first 100,000 characters so that the page stays responsive; "Copy Base64" and "Download" always give the complete text.
Tips and tricks
- ✓To get a shorter string, make the image smaller first with Compress Image or Resize Image, then encode the result.