DevBento logoDevBento
Tools/Base64 Encoder / Decoder/Data URI Generator: Create data: URLs from Files

Data URI Generator: Create data: URLs from Files

Generate data URIs from any file for inline HTML/CSS embedding. Supports images, PDFs, fonts, and more. Includes MIME type detection. 100% client-side.

📁

Drag & drop files here

or click to browse. Select multiple files at once. (max 50 MB each)

Related Tools
%20URL Encoder & HTML Entity Encoder
Encode and decode URLs with encodeURIComponent or encodeURI, and escape HTML special characters to named or numeric entities. Runs locally in your browser.
shaHash Generator
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes from text or files. Uses the browser's Web Crypto API for SHA hashes with a pure JS fallback for MD5.

Data URI Generator

A data URI embeds file content directly in an HTML attribute or CSS property, replacing an external URL with the file data itself. This tool generates data URIs from any file by reading it locally, detecting its MIME type, and encoding the content as Base64. For all Base64 tools and reference material, visit the Base64 Hub.

How to Use

  1. Drop a file onto the upload area or click to browse
  2. The tool detects the MIME type and encodes the file
  3. The “Data URI” output format is selected by default
  4. Copy the complete data URI

Data URI Syntax

Every data URI follows this structure:

data:[<mediatype>][;base64],<data>

Examples:

data:image/png;base64,iVBORw0KGgoAAAANSU...
data:text/html,%3Chtml%3E%3Cbody%3EHello%3C/body%3E%3C/html%3E
data:text/plain;charset=utf-8,Hello%20World

Where Data URIs Work

HTML img tags

<img src="data:image/png;base64,iVBORw0KGgo..." alt="Inline image" />

CSS backgrounds

.icon {
  background-image: url(data:image/svg+xml;base64,PHN2Zy...);
}

HTML anchor downloads

<a href="data:application/pdf;base64,JVBERi..." download="document.pdf">
  Download PDF
</a>

Favicons

<link rel="icon" href="data:image/svg+xml;base64,PHN2Zy..." />

Iframes

<iframe src="data:text/html;base64,PCFET0NUWVBF..." width="100%" height="400"></iframe>

JavaScript

const audio = new Audio('data:audio/mpeg;base64,SUQz...');
const img = new Image();
img.src = 'data:image/png;base64,iVBOR...';

Data URIs vs. External URLs

Aspect Data URI External URL
HTTP requests None One per resource
Caching Cannot cache independently Cached by browser
Size overhead +33% (Base64) None
First load Faster for small files Faster for large files
Repeat visits Re-downloaded with parent Served from cache
CSP compatibility Requires data: source Works by default
Gzip efficiency Poor (high entropy) Good (raw binary)

Content Security Policy

Content Security Policy (CSP) can restrict data URIs. A strict CSP without data: in the source list blocks data URIs:

Content-Security-Policy: img-src 'self';  /* blocks data: images */
Content-Security-Policy: img-src 'self' data:;  /* allows data: images */

If your application uses CSP, ensure the relevant directives (img-src, font-src, media-src, style-src) include data: if you use data URIs. Be aware that allowing data: in script-src is generally considered unsafe, as it enables inline script injection.

RFC 2397 and History

Data URIs were standardized in RFC 2397 (1998). The scheme was designed for including small data items inline in web documents, avoiding the overhead of separate HTTP transactions. Despite being nearly 30 years old, the specification remains unchanged and universally supported.

Practical Size Guidelines

Resource type Recommended max for data URI
Favicon 10 KB
CSS icon / sprite 5 KB
Small UI image 10 KB
Font subset 20 KB
Audio clip 100 KB
Any other file 10 KB (unless single file export)

Above these thresholds, separate files with HTTP caching deliver better overall performance.

For specific file types, see Image to Base64, PDF to Base64, Audio to Base64, or the CSS Background Image generator.

🔒

Nothing you paste leaves this tab. Every tool runs entirely in your browser — no upload, no server, no account.

© 2026 devbento.dev · built local-firstChangelog