How to convert an image to Base64
- Add an image.
- Pick the format you need: data URI, raw Base64, an img tag or a CSS rule.
- Press Copy and paste it into your code.
Good to know
- Base64 makes the data about 33 percent bigger than the file, because three bytes become four characters.
- It is worth it for tiny icons because it saves a request. For larger pictures a normal file is better, since it can be cached.
- A data URI can be pasted straight into a browser address bar to view the picture.
Questions
What is a data URI?
A web address that contains the file itself, in the form data:image/png;base64, followed by the encoded picture.
When should I not use it?
For anything larger than a few kilobytes. It bloats your page and cannot be cached on its own.
Is it encryption?
No. Base64 is just a way of writing bytes as text. Anyone can decode it.