Data URI generator — inline SVG, CSS, JSON or text as data URLs

Paste SVG, CSS, JSON, HTML or plain text, pick its MIME type, and get a data URI you can drop straight into an img src, a CSS url() or a link, with no separate file.

Live demo · real result from this tool
Encoding

Your result appears here.

Processed on your device — nothing is uploaded.

How to use the data URI generator

  1. Paste your content into Content, for example an SVG icon or a short CSS rule.
  2. Choose the MIME type: text/plain, text/html, text/css, text/csv, text/javascript, application/json, application/xml or image/svg+xml.
  3. Pick the Encoding: URL-encoded or Base64.
  4. Leave Add ;charset=utf-8 for text types ticked unless you need the shortest possible URI and your content is pure ASCII.
  5. Copy the Data URI. You also get its length, the content size in bytes, an image preview for SVG and a ready @import line for CSS.

What it does and when to use it

A data URI puts a small file directly inside a URL, so the browser does not have to fetch it separately. Typical uses:

  • An SVG icon or background inside a CSS file, with no extra request.
  • A tiny JSON or CSV file offered as a download link.
  • A test fixture or a quick HTML page loaded into an iframe.
  • Email templates or single-file demos that must not depend on other files.

For raster images such as PNG and JPEG, use the image to Base64 tool, which reads the image file. To check what a data URI contains, the Base64 decoder accepts the data:…;base64, prefix. For general URL escaping, use the URL encoder.

How it works

The format comes from RFC 2397: data: followed by the MIME type, optional parameters such as ;charset=utf-8, an optional ;base64 marker, a comma, and the data.

  • Base64: the content is turned into UTF-8 bytes and Base64-encoded.
  • URL-encoded SVG: whitespace runs are collapsed to one space, double quotes become single quotes (or %22 and %27 when the SVG contains an apostrophe), and only the characters that break URLs or CSS, such as <, >, # and %, are percent-encoded. This keeps SVG short and readable.
  • URL-encoded, other types: standard percent-encoding of everything except letters, digits and -_.~.

Everything runs in your browser.

Worked examples

Hello, world!  (text/plain, Base64)
→ data:text/plain;charset=utf-8;base64,SGVsbG8sIHdvcmxkIQ==

<svg xmlns="http://www.w3.org/2000/svg"><rect width="4" height="4" fill="#f00"/></svg>
(image/svg+xml, URL-encoded, no charset)
→ data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='4' height='4' fill='%23f00'/%3E%3C/svg%3E

body{color:red}  (text/css, URL-encoded)
→ @import url("data:text/css;charset=utf-8,body%7Bcolor%3Ared%7D");

The SVG result is 119 characters, against 142 for the same SVG in Base64. Note how #f00 became %23f00: an unescaped # would end the URL.

Limits and tips

  • The content is treated as text. Binary files such as PNG or fonts cannot be pasted here.
  • Keep data URIs small. Large ones slow down the first render of the page that contains them.
  • In CSS, wrap the URI in quotes: url("data:…").

Frequently asked questions

Should I use URL encoding or Base64 for SVG?
URL encoding is usually smaller for SVG and stays readable. In the example on this page, the same 86-byte SVG gives a 119-character URL-encoded URI and a 142-character Base64 URI. Base64 is the safer choice for content with many special characters.
Why did my double quotes turn into single quotes?
For SVG with URL encoding, double quotes are switched to single quotes so the data URI can sit inside a CSS url("…") or an HTML attribute without breaking out of its quotes. SVG accepts either kind of quote. If the SVG already contains an apostrophe, both kinds are percent-encoded (%22 and %27) instead, so a value like Smith's is not cut short.
When do I need ;charset=utf-8?
When the content is text that may contain non-ASCII characters, such as accented letters or emoji. Without it, some programs guess the wrong character set. The option only applies to text types, including SVG, JSON and XML.
Why does an HTML data URI not open when I paste it into the address bar?
Browsers block top-level navigation to data URLs for safety. Use an HTML data URI as the src of an iframe or in a download link instead. The tool reminds you of this when you pick text/html.
Is a data URI always better than a separate file?
No. Data URIs save a request but cannot be cached on their own and make your HTML or CSS bigger. They suit small icons and snippets. Above 32,000 characters the tool warns that a normal file is usually better.

Sources

  1. RFC 2397: The "data" URL scheme — IETF / RFC Editor, accessed 2026-10-08

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close