Convert any image to a Base64 data URI for embedding in HTML, CSS, or JavaScript. Supports PNG, JPG, GIF, SVG, WebP, BMP, ICO.
Base64 Encoder, URL Encoder, Hash Generator, JSON Formatter, and 25+ more tools.
Browse All Tools →Base64 encoding converts binary image data into ASCII text, allowing you to embed images directly in HTML, CSS, or JavaScript without external file requests. This reduces HTTP requests and can speed up page loads for small images.
/* CSS — background image */
.icon {
background-image: url(data:image/png;base64,iVBOR...);
background-size: contain;
}
<!-- HTML — inline image -->
<img src="data:image/png;base64,iVBOR..." alt="icon">
// JavaScript — create from file
const reader = new FileReader();
reader.onload = () => console.log(reader.result);
reader.readAsDataURL(file);
# Python — encode image
import base64
with open("image.png", "rb") as f:
encoded = base64.b64encode(f.read()).decode()
data_uri = f"data:image/png;base64,{encoded}"
Base64 is a binary-to-text encoding scheme that converts binary data (like image files) into a string of ASCII characters. It uses 64 characters (A-Z, a-z, 0-9, +, /) to represent binary data. Base64-encoded images can be embedded directly in HTML, CSS, or JSON as a data URI, eliminating the need for separate HTTP requests to load image files.
Use Base64 for small images under 10KB — icons, logos, and UI elements that are always needed on page load. Embedding them eliminates an HTTP request, which can speed up initial render. Avoid Base64 for large images: the encoded size is about 33% larger than the original, and large Base64 strings slow down HTML parsing and prevent browser caching benefits.
Base64 encoding increases file size by approximately 33%. This is because Base64 represents 3 bytes of binary data as 4 ASCII characters. A 100KB image becomes about 133KB when encoded. The overhead is acceptable for small files embedded inline, but for large images it significantly impacts page weight compared to serving static files with caching and compression.
Use a data URI as the src attribute: <img src="data:image/png;base64,[base64string]">. Replace [base64string] with the encoded output from this tool. For CSS backgrounds, use background-image: url('data:image/png;base64,[base64string]'). The MIME type (image/png, image/jpeg, etc.) must match the actual image format for browsers to render it correctly.
This tool supports PNG, JPEG/JPG, GIF, SVG, WebP, BMP, and ICO image formats. Simply drag and drop or click to upload any supported image file. The tool instantly generates the data URI, img tag, CSS background, and raw Base64 string. All processing is 100% client-side — your images are never uploaded to any server and remain private.