Convert images to Base64 encoded strings and data URIs for embedding directly in HTML, CSS, and email templates. Drag and drop or select any image file — PNG, JPG, SVG, GIF, WebP, AVIF. Get ready-to-use HTML <img> tags and CSS background-image code. Reduce HTTP requests by inlining small images. All encoding happens in your browser using the FileReader API — no images are uploaded to a server.
Click to select an image or drag and drop
PNG, JPG, SVG, GIF, WebP · Max 10 MB
A Base64-encoded image is just a regular image file translated into 64 ASCII characters and embedded inline in your HTML or CSS. The browser decodes it on the fly and renders it just like a fetched file. The trade is intuitive: you trade a network request for a larger document. Whether that trade pays off is more nuanced than the usual "use it for tiny images" rule of thumb suggests. This guide walks through how the encoding actually works (RFC 4648), what it costs in bytes and parser time, the specific cases where inline data URIs win, and the cases where they silently slow your page down.
Base64 (RFC 4648) is a binary-to-text encoding. It takes 3 input bytes (24 bits) and emits 4 output characters (24 bits worth, at 6 bits each). The 64-character alphabet is A–Z a–z 0–9 + /, plus = as padding. A picture of the math:
0x4D 0x61 0x6E = "Man"010011 010110 000101 101110T W F u → "TWFu"The 33% size overhead is unavoidable: 4 output bytes / 3 input bytes = 1.333. A 30 KB PNG becomes a 40 KB Base64 string. After gzip compression Base64 closes some of the gap (around 70–80% of the source size compresses well), but the inflated payload is what the browser parser has to walk.
A data URI (RFC 2397) is the specific URL scheme that lets you put inline content where a URL is normally expected. The structure:
data:[<mediatype>][;base64],<data>
Real examples:
data:image/png;base64,iVBORw0KGgoAAA… — most common, PNG inline.data:image/svg+xml;base64,PHN2Zy… — SVG inline; usually better as plain SVG (skip the encoding overhead).data:image/svg+xml;utf8,<svg…> — uncoded SVG; smaller than Base64 but breaks if SVG contains #, ?, or ".data:text/html;charset=utf-8,<h1>Hi</h1> — full inline HTML page.Most browsers cap data URIs at ~32 KB in CSS and ~2 MB in HTML in practice. Older Edge and IE truncated at 4 KB; if you support old Microsoft browsers, keep inline assets under that.
| Scenario | Inline as Base64? | Why |
|---|---|---|
| One-pixel tracking GIF | Yes | Sub-100-byte payload; saves a request. |
| Tiny UI icon (< 2 KB) used on every page | Yes | Critical render path; HTTP request overhead exceeds size cost. |
| HTML email template | Yes | External images blocked by default in most clients. |
| SVG icon set | Use inline SVG, not Base64 | Skip 33% encoding overhead; SVG is already text. |
| Hero image (50–500 KB) | No | Blocks parsing, blows out HTML, defeats CDN caching. |
| Photo gallery | No | Same as above; lazy-load with loading="lazy" instead. |
| Brand logo on every page | No | External file caches once; inline copies repeat per HTML response. |
| Image inside generated PDF / single-file HTML report | Yes | Self-contained document is the goal. |
img-src 'self' blocks data URIs unless you add data: — which weakens the policy.The picker handles the browser case. For build pipelines, here is the same conversion in code:
const fs = require('fs');
const buf = fs.readFileSync('icon.png');
const dataUri = `data:image/png;base64,${buf.toString('base64')}`;import base64, mimetypes
mime = mimetypes.guess_type('icon.png')[0]
data = base64.b64encode(open('icon.png','rb').read()).decode()
print(f"data:{mime};base64,{data}")import ("encoding/base64"; "net/http"; "os")
b, _ := os.ReadFile("icon.png")
mime := http.DetectContentType(b)
fmt.Printf("data:%s;base64,%s", mime, base64.StdEncoding.EncodeToString(b))$data = file_get_contents('icon.png');
$mime = mime_content_type('icon.png');
$uri = "data:$mime;base64," . base64_encode($data);require 'base64'
require 'mime/types'
data = Base64.strict_encode64(File.binread('icon.png'))
mime = MIME::Types.type_for('icon.png').first.to_s
"data:#{mime};base64,#{data}"echo "data:image/png;base64,$(base64 -w 0 icon.png)"SVG is already a text format. Base64-encoding it adds 33% with zero benefit. Two better options:
<svg viewBox="…">…</svg> directly in HTML. Smallest, fully styleable with CSS, animatable.url("data:image/svg+xml;utf8,<svg …/>") with #, ", and % percent-encoded. Smaller than Base64.For a 1 KB SVG icon, the URL-encoded form is ~1 KB; the Base64 form is ~1.33 KB; the inline element is ~1 KB and lets you change fill on hover. Inline wins when you can.
<link rel="preload"> instead.data:base64,iVBOR… (no image/png) renders nothing in most browsers.+ and / just fine, but URL Base64 (RFC 4648 §5) uses - and _ instead. Don't mix the two encodings.alt by mistake — accessibility tools then read out 50 KB of garbage.data:image/png;base64,iVBOR.... This eliminates the need for a separate HTTP request to load the image file — the image data is inline in the document itself.<img src="data:image/png;base64,iVBOR..." alt="description">. CSS: background-image: url('data:image/png;base64,iVBOR...'). The data URI includes the MIME type prefix so the browser knows how to render the image. Always add meaningful alt text for accessibility and SEO.image/png, image/jpeg, image/svg+xml). Note: SVG files are often more efficient as inline <svg> elements rather than Base64, since SVG is already text-based.All tools run in your browser, no signup required, nothing sent to a server.