What a data URI is and when to use one
A data URI embeds a file’s binary content directly inside a text string,
formatted as data:[MIME type];base64,[encoded bytes]. Instead of linking to
a separate image file with a URL, you put the image itself into your HTML, CSS,
Markdown, or JSON. The browser decodes and renders it identically to a regular
image link — no extra HTTP request needed.
Practical uses include:
- Email templates: embed small logos and icons so they appear even when an email client blocks external image requests.
- Self-contained HTML files: a single
.htmlfile that contains all its images without needing a folder of assets alongside it. - Offline or local demos: no server required; the images travel with the markup.
- CSS sprites replacements: a single small icon as a CSS
background-imagewithout a separate image file. - Markdown with embedded images: some tools (Obsidian, Notion exports) accept data URIs directly in Markdown image syntax.
How this tool generates the URI
The browser’s FileReader.readAsDataURL reads your file’s raw bytes and encodes
them as base64 without re-compressing or altering the image. The output format is:
data:[MIME type];base64,[base64 encoded bytes]
For a PNG icon: data:image/png;base64,iVBORw0KGgoAAAANS...
The tool then wraps that URI in your chosen output format:
| Output option | Result |
|---|---|
| Raw data URI | data:image/png;base64,... |
| HTML img tag | <img src="data:image/png;base64,..." alt=""> |
| CSS background | background-image: url("data:image/png;base64,...") |
The size overhead
Base64 encoding represents 3 bytes as 4 characters, adding roughly 33% to the original file size. A 1.2 KB icon becomes about a 1.6 KB string in the page. For small icons and tiny graphics, this overhead is negligible and the trade-off of eliminating a network request often wins.
For large photographs (50 KB+), the 33% overhead and the cost of embedding a large string into your HTML source usually makes a normal image URL a better choice. Data URIs also cannot be cached independently by the browser — the parent document must be re-fetched to get an updated version.
Browser and email client support
All major web browsers support data URIs in <img> tags and CSS
background-image. In email, support is broader than it used to be, but some
clients (parts of Microsoft Outlook on Windows) may block or strip inline base64
images — always test in your target email clients before relying on data URIs
for marketing emails.
Your image is read locally with the FileReader API and is never uploaded, stored, or transmitted anywhere.