b2KIT

Data URI Generator

Convert files to data URIs and data URIs back to files for inline embedding in HTML and CSS.

Tested tool guide Tested browser tools Checked August 16, 2026

What Data URI Generator does, with a checked example

A data URI inlines a file's bytes into a URL: the `data:[mediatype][;base64],<payload>` scheme lets an `<img>` src or a CSS `url()` carry an image, font, or stylesheet with no separate file and no network request. This tool converts files into that form and converts URIs back into files. Encoding reads the file, base64-encodes its bytes, and prepends a MIME type guessed from the filename; decoding reverses each step. The surprise for most users: the result is bigger than the source, roughly a third larger for base64, before the prefix and mediatype add anything.

Worked example

A concrete input and expected output from the current implementation.

Input

A text file named hello.txt containing: Hello, world!

Expected output

data:text/plain;base64,SGVsbG8sIHdvcmxkIQ==

The 13 bytes of "Hello, world!" encode as 18 base64 characters: each three-byte group becomes four characters, and the single leftover byte yields two characters plus == padding. The tool prepends data:text/plain;base64,, using text/plain as the MIME type inferred from the .txt extension.

How the result is produced

1

File to URI

The file's bytes are base64-encoded: every three bytes become four characters from the base64 alphabet, with = padding at the end of the payload. The tool guesses a MIME type from the file extension (.png -> image/png, .svg -> image/svg+xml) and assembles data:<type>;base64,<payload>. Unrecognized extensions fall back to a generic type such as application/octet-stream; you can usually override the guess before copying.

2

URI to file

Pasting a data URI runs the reverse direction. Everything before the first comma is the header: the scheme, the mediatype, and optionally the ;base64 marker. If the marker is present the payload is base64-decoded; otherwise it is percent-decoded, turning %20 back into a space and %2F into a slash. The mediatype in the header decides the suggested filename extension (image/png -> .png, font/woff2 -> .woff2) when you save the recovered bytes.

Good uses

  • Bundle a small image, icon, or font into a single HTML file that works offline or forwards as one attachment, with no server and no missing-asset failures.
  • Inline a tiny asset into CSS - background-image, cursor, or @font-face src - so the page renders it with zero extra HTTP requests.
  • Recover a file from a data URI found in page source, a saved email, or an exported HTML document, without scripting the decoding yourself.

Limits and checks

  • Size grows on encode. Base64 emits 4 characters per 3 bytes, about 33% more, plus the data: prefix and MIME type; a 100 KB image becomes roughly 133 KB of text. Percent-encoded payloads are worse for binary data, which usually triples in size.
  • Strict contexts reject data URIs. A Content-Security-Policy that does not allow data: in img-src or style-src blocks them without error, and some email clients strip inline images from messages. Test in the actual target, not just in a local tab.
  • The MIME type is inferred from the filename extension, not the file contents. A .png renamed to .jpg encodes with the wrong mediatype and may download instead of rendering; decoding a URI whose header lies about the type yields a file that misbehaves. Also, a URI without ;base64 is percent-encoded - a base64 decoder will turn it into garbage.

Common questions

Why is the data URI bigger than my original file?

Base64 alone adds a third: 3 bytes become 4 characters. On top of that come the data: prefix and the MIME type, and percent-encoding makes binary data roughly three times larger because most bytes expand to %XX. For a few kilobytes of icons the overhead is acceptable; beyond a few hundred kilobytes, a real file is almost always the better choice.

Does encoding my file upload it anywhere?

No. The conversion happens entirely in the browser: bytes are read from the file you selected, encoded in memory, and never transmitted. The same applies in the decode direction. That is useful for sensitive content, but remember the output URI embeds the whole file - treat a copied URI with the same care as the file itself.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools