Encoding · Developer

Data URI generator.

Turn a file or text into a data: URI, or paste one to decode it, sniff its real type and preview it. Files are read in your browser and never uploaded.

Advertisement

Input

Mode
Read locally. A chosen file overrides the text box.
Filled from the file when you pick one. Leave empty to omit it (RFC 2397 then assumes text/plain;charset=US-ASCII).
Encoding

Result

Choose a file or enter text, then press Run.

How a data URI is built

RFC 2397 defines the form data:[<mediatype>][;base64],<data>. If the media type is omitted it defaults to text/plain;charset=US-ASCII. With ;base64 the payload is Base64; without it, bytes outside the safe URL range are written as %xx escapes.

Size overhead: Base64 turns every 3 bytes into 4 characters (padded), so n bytes become 4×ceil(n/3) characters, roughly 33% more (RFC 4648 section 4). Percent-encoding costs 3 characters per escaped byte, so it wins for mostly-ASCII text and SVG and loses for binary files. The RFC itself notes data URIs are only useful for short values.

MIME sniffing: when decoding, the tool checks the first bytes against the signatures in the WHATWG MIME Sniffing Standard (PNG, JPEG, GIF, WebP, WAVE, PDF) and looks for an <svg root for SVG text. It warns when the declared type and the detected type disagree. A detected type is a guess about the bytes, not proof of what the file is.

Sources: RFC 2397 — The "data" URL scheme, MDN — data: URLs, RFC 4648 section 4 — Base64, WHATWG MIME Sniffing Standard.

Frequently asked questions

Is my file uploaded?

No. The file is read with your browser's FileReader and encoded locally. Nothing is sent anywhere.

When should I use percent-encoding instead of Base64?

For short, mostly-ASCII content such as inline SVG, percent-encoding is usually smaller because Base64 always adds about a third. For binary files such as PNG or JPEG, Base64 is smaller. The result panel shows both lengths for your input.

How is this different from the Base64 text tool?

The Base64 text tool converts plain strings only. This one builds and parses the full data: URI: media type, parameters, encoding flag, file input, type detection and preview.

Detected type is a guess

Sniffing looks at the leading bytes only. A matching signature does not prove a file is safe or valid, and previews of untrusted data are rendered as inert images or escaped text, never executed.

Advertisement
Advertisement
Listening…