File to Data URI
Encode an image, font or any file as a data: URI ready to inline in HTML or CSS.
Add a file
JSON, XML, text or any file you want to encode, decode or hash.
Choose an output
Encode an image, font or any file as a data: URI ready to inline in HTML or CSS.
About File to Data URI
This tool encodes a file as a data: URI, in the form data:<mime type>;base64,<data>, that you can paste directly into an HTML src attribute or a CSS url(). The MIME type is taken from the file, or guessed from its extension, and the summary shows the size before and after encoding.
When it helps
- Inlining a small icon or logo in CSS to avoid an extra HTTP request.
- Embedding images in a single-file HTML report or email template.
- Including a small font or image in a JSON config or test fixture.
Tips
- Base64 adds about 33 percent to the size, and inlined assets cannot be cached separately. Keep data URIs for small files.
- For SVG, a URL-encoded data URI is often smaller than Base64, but this tool always produces Base64, which works everywhere.
- If the MIME type comes out as application/octet-stream, browsers may not display the file. Edit the type in the output, for example to image/png.
Good to know
Quick answers about file to data uri in your browser.
In HTML, put it in the src attribute: <img src="data:image/png;base64,...">. In CSS, use background-image: url("data:image/png;base64,...").
Modern browsers handle large data URIs, but they bloat your HTML or CSS and slow parsing. Some email clients strip them entirely, so test before relying on them in email.
Yes. There is no sign-up, no watermark and no limit on how many files you process.
No. Files are read and processed locally in your browser, so they never leave your device.
Related tools
Part of the Developer Utilities collection.