Developer guide
How to Encode an Image in Base64
Learn how image bytes become a data URL and when embedding an image is practical.
A Base64 image data URL stores the image bytes inside a text string. This can make a small asset self-contained, but it also makes the text longer and harder to cache independently.
The data URL shape
A data URL includes the media type, an encoding marker, and the Base64 payload. For a PNG, the prefix identifies the content as image/png before the encoded bytes begin.
Keep embedded images small
Inline assets can reduce separate requests for tiny icons or email content. Large photos are usually better served as normal files so browsers can cache, stream, and reuse them efficiently.
Mind the source
Use a trusted image and preserve its correct MIME type. Base64 does not sanitize image content or make an untrusted upload safe to process.
Put it into practice
Encode an image