Converting an image to Base64 means taking the raw binary data of an image file (PNG, JPEG, SVG, etc.) and encoding it into a long ASCII string using the Base64 alphabet. This string can then be embedded directly into HTML, CSS, or JSON — no separate file download required.
The result looks like a data: URI: data:image/png;base64,iVBORw0KGgoAAAANSUhEUg.... The browser decodes this inline and renders the image without making a separate HTTP request.
<img src> references.<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." alt="Icon">
The data: URI format is: data:[mediatype][;base64], followed by the encoded string. The MIME type must match the image format — image/png, image/jpeg, image/svg+xml, image/webp, etc.
.icon {{
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0...");
width: 24px;
height: 24px;
}}
This is especially useful for small SVG icons in component libraries where you want zero external dependencies.
{{
"image": "data:image/png;base64,iVBORw0KGgo...",
"name": "product-photo.png"
}}
APIs sometimes return Base64-encoded images. Keep in mind this roughly triples the JSON payload size compared to a binary response.
The key trade-off is requests vs. size. Base64 eliminates an HTTP request but increases the document size by ~33%. For tiny images, the request elimination wins. For large images, the size increase hurts — especially on slow connections where downloading a large HTML document blocks rendering.
Modern best practice: use Base64 only for images under 2–4 KB. For everything else, use separate files with proper caching headers and lazy loading.
SVGs can be embedded as Base64, but you can also use UTF-8 encoding directly: data:image/svg+xml,%3Csvg...%3E. This is smaller than Base64 and more readable, though you must URL-encode special characters. RiseTop's image-to-Base64 tool handles both approaches automatically.