Xerobit

Data URI Generator: Encode and Decode Data URLs

A data URI generator converts text, SVG, JSON, CSS or HTML into an inline data URL you can embed directly in your code. Choose base64 or percent-encoding, pick a MIME type, and see the result instantly. You can also decode a data URL back to its original content. Everything runs in the browser, so nothing is uploaded to a server.

Result

data:text/plain;base64,
  • Data URI
    data:text/plain;base64,
  • Original size
    0 bytes
  • URI length
    23 characters

How to use the data uri generator

  1. Select Encode to convert text to a data URI, or Decode to reverse one.
  2. Paste your source text, SVG, JSON, CSS or HTML into the input area.
  3. Pick the correct MIME type for your content from the dropdown.
  4. Choose Base64 for compact opaque output or Percent-encoded for output you can still read.
  5. Copy the generated data URL from the output field.

How a data URI works

A data URI follows the format defined in RFC 2397: data:[<mediatype>][;base64],<data>. The mediatype tells the browser how to interpret the payload. When the ;base64 token is present, the data portion is base64-encoded. Without it, the data is either plain ASCII or percent-encoded.

For example, converting the string Hello with this data URI generator produces data:text/plain;base64,SGVsbG8=. The base64 alphabet maps every three bytes of input into four printable characters, making it safe for embedding in HTML attributes, CSS url() functions and JavaScript strings.

Base64 versus percent-encoding

When you use a data url generator, you must choose between two encoding strategies. Base64 is the standard choice for binary content like images and fonts because it handles any byte value safely. It increases the payload size by roughly 33 percent.

Percent-encoding replaces special characters with %XX hex sequences. It keeps plain ASCII text mostly readable and is often shorter than base64 for simple strings. However, it is not suitable for raw binary data. For text to data URI conversions involving only ASCII characters, percent-encoding can produce cleaner output.

FeatureBase64Percent-encoded
Binary safeYesNo
Size overheadAbout 33%Varies by character
ReadabilityOpaquePartially readable
Best forImages, fonts, SVGShort ASCII text

Common MIME types for inline data

Choosing the right MIME type ensures the browser processes your embedded content correctly. Here are the most common types used with a data URI generator:

MIME typeUse case
text/plainPlain text snippets
text/htmlInline HTML fragments or full documents
text/cssStylesheets embedded in link tags or style attributes
application/jsonJSON payloads for testing or configuration
image/svg+xmlScalable vector graphics in img tags or CSS backgrounds

If you omit the MIME type, browsers default to text/plain;charset=US-ASCII, which may cause rendering issues for HTML or SVG content.

Practical uses for data URLs

Data URIs eliminate extra HTTP requests by embedding resources directly in the document. Common scenarios include small icons in CSS background-image properties, single-file HTML emails where external images are blocked, and self-contained SVG files that carry their own styles.

Developers also use them to pass configuration or sample payloads without hosting separate files. If you need mock payloads for testing APIs, pairing this tool with a random sample data generator lets you quickly encode generated fixtures as inline data URLs.

Keep in mind that large data URIs increase the HTML document size and prevent the browser from caching the resource independently. A practical threshold is around 4 KB to 8 KB per resource. Beyond that, serving a separate file is usually more efficient.

Decoding data URIs

This tool also works as a decoder. Paste any valid data: URL into the input field, switch to Decode mode, and the original content appears immediately. The parser extracts the MIME type, checks for the ;base64 flag and reverses the encoding accordingly.

Decoding is useful when inspecting third-party code, debugging CSS background images or verifying that a generated URI round-trips correctly. You can check the decoded length against a character counter to confirm no data was lost during encoding.

Worked examples

ExampleInputResult
Plain text to base64 data URIMode: encode; Input: Hello, world!; MIME type: text/plain; Encoding: base64Data URI: data:text/plain;base64,SGVsbG8sIHdvcmxkIQ==; Original size: 13 bytes; URI length: 43 characters
Inline SVGMode: encode; Input: <svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><rect fill='red' width='10' height='10'/></svg>; MIME type: image/svg+xml; Encoding: base64Data URI: data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPScxMCcgaGVpZ2h0PScxMCc+PHJlY3QgZmlsbD0ncmVkJyB3aWR0aD0nMTAnIGhlaWdodD0nMTAnLz48L3N2Zz4=; Original size: 110 bytes; URI length: 174 characters
JSON payloadMode: encode; Input: {"key":"value"}; MIME type: application/json; Encoding: base64Data URI: data:application/json;base64,eyJrZXkiOiJ2YWx1ZSJ9; Original size: 15 bytes; URI length: 49 characters
Decode a data URLMode: decode; Input: data:text/plain;base64,SGVsbG8sIHdvcmxkIQ==; MIME type: text/plain; Encoding: base64Decoded text: Hello, world!; Detected MIME: text/plain; Encoding used: base64; Decoded size: 13 bytes

FAQ

What is a data URI?

A data URI is a Uniform Resource Identifier that embeds content directly in the URL string using the scheme data:. It lets you include small files inline in HTML, CSS or JavaScript without a separate network request.

Should I use base64 or percent-encoding?

Base64 is the usual choice for binary data like images or fonts, but this page encodes text only: it converts the text you paste to UTF-8 bytes first, so non-ASCII characters work in both modes. Use percent-encoding for short text where readability matters, and base64 for longer or multi-line content.

Do data URIs work in all browsers?

Yes. Every modern browser supports data URIs in img src attributes, CSS url() functions, iframes and anchor hrefs. Internet Explorer 8 supported them with a 32 KB limit.

Is there a size limit for data URIs?

The specification does not define a hard limit, but browsers may cap URI lengths. In practice, keeping data URIs under 4 KB to 8 KB avoids performance issues and compatibility problems.

Can I use this data URI generator offline?

Yes. The tool runs entirely in your browser using JavaScript. No data is sent to any server, so it works offline and keeps your content private.

How do I embed an SVG as a data URL in CSS?

Set the MIME type to image/svg+xml, encode your SVG markup with base64, then use the result in your stylesheet: background-image: url('data:image/svg+xml;base64,...');.

Can this data URI generator encode an image file?

No. It takes pasted text (including SVG markup) and does not read files. To embed a PNG or JPEG you need to base64-encode the file bytes and prefix them with data:image/png;base64, yourself.