SVG Data URI Encoder

Paste SVG markup and get a live preview plus base64 and URL-encoded data URIs, with ready-to-paste <img> and CSS background snippets. Runs entirely offline; your markup never leaves the browser and persists here via localStorage.

SVG Markup

How It Works

Base64 vs. URL-encoding

An SVG can be embedded directly in an <img src> or a CSS url() as a data URI, saving an HTTP request. There are two encodings. Base64 (data:image/svg+xml;base64,…) is universally safe but inflates the payload by about 33%. URL-encoding (data:image/svg+xml,…) keeps the markup as text with only the reserved characters escaped, so for SVG — which is mostly ASCII — it is almost always smaller and stays human-readable. This tool shows both sizes so you can pick; URL-encoding usually wins for inline SVG.

The encoding details

Base64 is UTF-8 safe here (the markup is UTF-8 encoded before btoa, so non-ASCII characters survive). The URL-encoding follows the widely used minimal scheme: double quotes become single quotes (so the URI itself can sit in double quotes), whitespace between tags is collapsed, and only %#()<>?[\]^`{|} and newlines are percent-escaped — everything else stays readable. If your root <svg> is missing the xmlns="http://www.w3.org/2000/svg" namespace, the tool adds it (toggle above), because without it the browser won't render the data URI as an image.

Notes

References

  1. MDN — Data URLs (the data: URI scheme and base64). https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data
  2. The minimal SVG URL-encoding scheme popularized by Yoksel's “URL-encoder for SVG.”