Data URI Builder: Text to Base64 Data URL – Free

Paste text, name its media type, and this data URI builder returns a complete Base64 data URL. It suits HTML snippets, SVG source, CSS, JSON and plain text.

How to use the Data URI builder tool

  1. Paste the content into the Text box. Select Example to load Hello, world! with the media type text/plain.
  2. Enter the type in the Media type box, for example text/html or image/svg+xml. Leave it empty to get text/plain.
  3. Select Convert to build the data URL.
  4. Select Copy to take the data URL from the Result box, then paste it into an attribute or a stylesheet.

How the data URI builder assembles the URL

RFC 2397 defines the data scheme as data:, an optional media type, an optional ;base64 marker, a comma and the content. The builder fills that pattern in a fixed way: it encodes your text as UTF-8, converts the bytes to standard padded Base64 and joins the pieces.

The payload is always Base64, never percent-encoded text. The media type is trimmed and otherwise used as typed, including its letter case. An empty Media type box falls back to text/plain.

data:text/plain;base64,SGVsbG8sIHdvcmxkIQ==
|    |         |       |
|    |         |       Base64 of the UTF-8 text
|    |         marker
|    media type
scheme

Two worked examples

The first is the built-in sample. The second turns a one-rule stylesheet into a URL that can be used as the href of a stylesheet link.

Text:        Hello, world!
Media type:  text/plain
Result:      data:text/plain;base64,SGVsbG8sIHdvcmxkIQ==

Text:        h1{color:red}
Media type:  text/css
Result:      data:text/css;base64,aDF7Y29sb3I6cmVkfQ==

Media type rules and limits

The Media type box is validated before anything is built. A value that fails stops with Enter a valid media type such as text/plain.

  • The value must be a type and a subtype with one slash between them, such as application/json.
  • Letters, digits, underscores, the exclamation mark and the characters # $ & ^ . + - are allowed, so application/vnd.api+json passes.
  • Parameters are not accepted. text/html;charset=utf-8 is rejected, and so is a wildcard such as text/*.
  • Input is text only. For an image or another binary file, use Image to Base64 or the CSS Data URI Converter.
  • Empty text is allowed and produces a data URL with nothing after the comma.

Character sets and where text data URLs are used

Because parameters are rejected, the result carries no charset. The only default RFC 2397 defines is US-ASCII, so a consumer may misread accented letters or emoji. To be explicit, insert ;charset=utf-8 by hand between the media type and ;base64 after copying.

Typical uses are an iframe src holding a small HTML document, an SVG icon in an img src or a CSS url(), a download link for generated CSV or JSON, and inline source maps, which are application/json data URLs. Browsers block links that navigate the top-level page to a data URL.

Frequently asked questions

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

They are two names for the same thing. RFC 2397 calls it the data URL scheme, and URI is the broader term that includes URLs. Browsers, CSS and HTML treat both words as referring to strings that begin with data:.

Can I add charset=utf-8 in the Media type box?

No. The box accepts only type/subtype and reports an error if a semicolon is present. Build the URL first, then edit the copied result so it reads, for example, data:text/html;charset=utf-8;base64, followed by the payload.

Can I build a data URI from an image file?

Not with this tool, because its input is a text box. SVG is the exception, since SVG is text: paste the source and enter image/svg+xml. For PNG, JPEG, GIF or WebP files, use the CSS Data URI Converter.

Why does the builder use Base64 and not percent-encoding?

Base64 handles every character, including quotes and line breaks, without any escaping rules to get wrong. The price is a third more length. For mostly ASCII content such as SVG, percent-encoding can be shorter, but this tool always outputs Base64.

What happens if I leave Media type empty?

The builder uses text/plain. The result starts with data:text/plain;base64, and a browser that opens it shows the content as unformatted text.

Related tools