Convert any image to Base64 for embedding in HTML or CSS. Get the full data URL or raw Base64 string — MIME type detected automatically, nothing uploaded.
Upload an image to convert it to Base64
Data URIs, standardized under RFC 2397, enable web developers and graphic designers to embed small image files directly inline within HTML, CSS stylesheets, or JSON API payloads. By converting binary image assets (such as PNG, JPEG, SVG, or WebP) into Base64 strings, web pages eliminate separate HTTP network requests for critical UI icons, logos, and email template assets.
data:[<mediatype>][;base64],<data>
| Image Format | Corresponding MIME Type | Data URI Prefix |
|---|---|---|
| PNG Image | image/png | data:image/png;base64,... |
| JPEG Image | image/jpeg | data:image/jpeg;base64,... |
| SVG Graphic | image/svg+xml | data:image/svg+xml;base64,... |
| WebP Image | image/webp | data:image/webp;base64,... |
| GIF Animation | image/gif | data:image/gif;base64,... |
JavaScript (Browser FileReader API)
function convertFileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
reader.readAsDataURL(file);
});
}
Python
import base64
def image_file_to_base64(image_path: str, mime_type: str = "image/png") -> str:
with open(image_path, "rb") as img_file:
encoded = base64.b64encode(img_file.read()).decode("utf-8")
return f"data:{mime_type};base64,{encoded}"
image/svg+xml, image/webp) so image decoders invoke the correct raster pipeline.This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.