Image to Base64 Converter
Encode a small image as a data URI for CSS or HTML, or paste Base64 to turn it back into a downloadable image.
Image to Base64
Small images (icons and logos under about 10 KB) are the best fit for inline data URIs.
Base64 back to an image
How to convert an image to Base64
- Click Choose an image and select a PNG, JPG, WebP, GIF or SVG file. The encoded result appears straight away.
- Check the summary line. It shows the original file size and how many characters the data URI contains.
- Copy the version you need. Copy data URI gives the raw value, Copy CSS gives a ready-made
background-imagerule, and Copy <img> gives a complete image tag, with alt text based on the file name.
To go the other way, scroll to Base64 back to an image. Paste a full data URI, or plain Base64 and choose its image type, then press Show image. You can check the preview and download the file.
Worked example
A web designer has a small 64 × 64 pixel red icon saved as a PNG of 206 bytes. She wants it inside her stylesheet, so the browser does not make a separate request for such a tiny file. After loading it, the summary reads "icon-64.png: 206 bytes file → 298 characters of data URI". The value begins data:image/png;base64,iVBORw0KGgo, and every PNG starts with those last few characters. The 298 characters are made up of the 22-character prefix plus 276 characters of Base64, which is about a third more than the original bytes.
To make sure nothing was lost, she pasted the data URI into the decoder and pressed Show image. It reported "image/png, 64 × 64 px, 206 bytes", an exact match with the original file.
How it works
Base64 is a way of writing any binary file using only 64 safe text characters: capital and small letters, digits, plus and slash. Every 3 bytes of the file become 4 characters of text, which is why encoded images are roughly 33% larger. A data URI adds a short label in front, stating that it is data, what type it is and that it uses Base64, so a browser knows how to display it. The tool reads your file with the browser's FileReader, and decodes pasted text back into bytes. Nothing is uploaded at any stage.
When to use data URIs
Inline images work well for very small, frequently used graphics, such as icons, bullet points, loading spinners and tiny background patterns. They are also useful for single-file HTML reports and some email templates. For photographs and anything larger than about 10 KB, a normal image file is better. It can be cached separately, loaded lazily and compressed efficiently, whereas Base64 inside a stylesheet is downloaded again every time the stylesheet changes.
Tips
- Optimise and resize the image before encoding it. Base64 makes any waste a third bigger.
- SVG icons can often be inlined as plain text instead of Base64, which is smaller still.
- Many email clients, including Gmail, block data URI images, so test before using them in newsletters.
- Replace the file-name alt text in the generated <img> tag with a short description, so screen readers can describe the image.
Frequently asked questions
Is Base64 a form of encryption?
No. Anyone can decode it instantly. It only changes how the data is written, not who can read it.
Why does my pasted Base64 fail to decode?
The text may be cut short, contain spaces or line breaks from an email, or use the wrong image type. Paste the complete value and check the type selector.
Is there a file size limit?
There is no fixed limit, but very large images produce millions of characters, which can make the page and your code editor slow. Keep inline images small; anything over about 100 KB is better as a normal file.
Can I use the CSS version in WordPress?
Yes. Paste the copied rule into Appearance, Customise, Additional CSS, or into your child theme's stylesheet, and add your own selector in front of it.
Are my images uploaded?
No. Both directions run locally on your device, and no file is ever uploaded.