Upload a file
  1. base64hub
  2. Web & token tools
  3. Data URI generator

Data URI Generator

Type text or drop a file to get a data: URI with the right MIME type and charset, then copy it as a raw URI, a CSS url(), an HTML tag or Markdown.

Free no sign-up, no limits Local nothing uploaded Snippets CSS, HTML, Markdown, @font-face Updated Oct 27, 2026
Payload –URI length –Overhead –

Processed in your browser. This page cannot send your data anywhere – how we know

How to create a data URI

  1. Choose a mode. From text (the default) encodes what you type or paste. From file takes a dropped, pasted or picked file of any type. Parse goes the other way and takes a URI apart.
  2. In From text, set MIME type (for example text/css or application/json), a Charset and the Encoding: Base64 or URL-encoded. In From file, the MIME type is filled in from the file and can be edited.
  3. Pick the Output format: Data URI, CSS url(), HTML <a> with a download name, or Markdown. HTML <img> appears for images and @font-face for fonts.
  4. Press Copy output. Download file saves the payload itself, and Save as .txt stores the output text.

Under the buttons, Payload is the size of the data, URI length the size of the result, and Overhead the difference in percent.

The data URI syntax

A data URI packs a whole file into a URL:

data:[<media type>][;charset=<charset>][;base64],<data>
PartExampleNotes
media typeimage/png, text/cssoptional; empty means text/plain;charset=US-ASCII
parameters;charset=utf-8for text types; more ;key=value pairs are allowed
;base64;base64the data is Base64; without it, it is percent-encoded
dataafter the commathe payload

A few examples:

Data URIContains
data:,Hello%2C%20World%21the text Hello, World!, type implied
data:text/plain;charset=utf-8;base64,SGVsbG8sIFdvcmxkIQ==the same text, Base64
data:text/css,body%7Bcolor:%23333%7Da CSS rule, URL-encoded
data:application/json;base64,eyJvayI6dHJ1ZX0={"ok":true}

The comma is mandatory, even when the data is empty: data:, is a valid, empty URI.

Base64 or URL-encoded

Both encodings produce a valid URI; they differ in size and readability.

PayloadBase64 URIURL-encoded URI
Hello, World! as text/plain;charset=utf-857 chars45 chars
body{color:#333} as text/css45 chars36 chars
{"ok":true} as application/json45 chars41 chars
<h1>Héllo</h1> as text/html;charset=utf-856 chars56 chars

Plain ASCII text is shorter URL-encoded, and you can still read it in the source. Every non-ASCII byte costs three characters (é is %C3%A9), so text in other scripts quickly favours Base64. For images, fonts, PDFs and other binary files, use Base64; the generator warns if you pick URL encoding for binary data.

The URL encoding here is conservative: letters, digits and - . _ ~ ! $ * + , ; = : @ / ? stay as they are, everything else is escaped, including #, %, quotes, parentheses and spaces. A raw # would end the URI, because browsers read it as the start of a fragment. For SVG there is a third, shorter option on SVG to Data URI.

Where data URIs work

  • Images in <img src>, CSS background-image, <link rel="icon"> and the poster of a video.
  • Fonts in @font-face src, handy for one small icon font. The generator builds the rule for you when the MIME type is a font.
  • Downloads through <a href="data:..." download="report.csv">, for files generated in a page without a server.
  • Stylesheets and scripts loaded with <link href> or <script src>, when the page’s Content Security Policy allows data: for them.
  • Test fixtures and JSON payloads that need a small file inline.

They do not work everywhere. Chrome and Firefox block page-initiated navigation of the whole tab to a data: URL, so a link to data:text/html,... does nothing when clicked. A Content Security Policy must list data: in img-src, font-src or the relevant directive. Many webmail clients, Gmail among them, drop data URI images entirely; see Base64 in email.

Size and performance

Base64 makes binary data about 33% larger, and the URI repeats with every page or stylesheet that contains it, without its own cache entry. That trade is good for small assets of a few kilobytes and bad for photos. Data URI performance goes through the numbers. For images in particular, Image to Base64 can resize and convert before encoding.

Build a data URI in code

URL-encoded text in JavaScript:

const uri = "data:text/plain;charset=utf-8," + encodeURIComponent("Prices: 5 € & up");
// data:text/plain;charset=utf-8,Prices%3A%205%20%E2%82%AC%20%26%20up

Base64 JSON in Python:

import base64, json

obj = {"name": "Ada", "langs": ["en", "fr"]}
uri = "data:application/json;base64," + base64.b64encode(json.dumps(obj).encode()).decode()
# data:application/json;base64,eyJuYW1lIjogIkFkYSIsICJsYW5ncyI6IFsiZW4iLCAiZnIiXX0=

More in Base64 in JavaScript and Base64 in Python. To inspect a data URI you found somewhere, use the Data URI Parser.

FAQ

What is the difference between a data URI and a data URL?

None in practice. RFC 2397 calls it the “data” URL scheme, and browsers and the Fetch standard say data URL; data URI is the older, equally common name for the same data: syntax.

When should I use URL encoding instead of Base64?

For short, mostly ASCII text such as CSS, JSON or SVG, URL encoding is often shorter and stays readable. For binary files Base64 is always smaller, since percent-encoding turns most bytes into three characters.

Do I need ;charset=utf-8 in a data URI?

For text with any non-ASCII character, yes. Without it, a text/plain data URI defaults to US-ASCII, and é or € can come out as two or three wrong characters. Images and other binary types do not take a charset.

Why does clicking my data: link open nothing?

Chrome and Firefox block pages from navigating the whole tab to a data: URL, because it was widely used for phishing. Images, stylesheets, fonts and downloads with <a download> still work.

Is there a size limit for data URIs?

Limits differ between browsers and are generous for images, but very long URIs make pages slow and some tools truncate them. The generator warns above 2 MB; for anything that large, link a file instead.