Skip to content
UniKit

SVG to Data URI

Turn SVG markup into a data:image/svg+xml URI (pick an .svg file or paste the markup): get both the Base64 and the URL-encoded form (with an optional minimal-escaping mode), compare their real character counts and copy a ready-to-paste CSS background-image snippet.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

The .svg file is read as UTF-8 text and encoded in your browser — nothing is uploaded.

Data URI preview

Pick a file or paste markup and the generated data URI renders the icon here.

Data URIs and real length comparison

Both character counts are measured: Base64 is always ~33% larger, percent-encoding is usually shorter with minimal escaping.

Pick a file or paste markup and both data URI forms show up here.

What this tool does

  • Inline an icon into CSS: paste the SVG markup and copy a background-image snippet, saving an extra request.
  • Compare both encodings: the Base64 and URL-encoded lengths are shown side by side so you can ship the shorter one.
  • The URL-encoded form stays readable — you can see fill, width and friends in your stylesheet, which makes colour tweaks easier.
  • The reverse case: paste an existing Data URL to see what it draws, re-encode it and preview the result.

Example

Input

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><rect width="24" height="24" fill="#0ea5e9"/></svg>

Output

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cmVjdCB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIGZpbGw9IiMwZWE1ZTkiLz48L3N2Zz4=

The Base64 form is 206 characters and the URL-encoded form 257 (181 with minimal escaping), so Base64 happens to be shorter for this sample — the result rows spell out which form wins. Choosing an .svg file works too (read as UTF-8 source) and the text result contains both URIs plus a ready-to-paste url("data:…").

Frequently asked questions

Base64 or URL-encoded?

They are functionally identical. Base64 adds a steady ~33% overhead but never breaks; the URL-encoded form is shorter for mostly-ASCII SVGs and stays readable, as long as #, <, > and " are escaped. The tool shows both lengths so you can pick the shorter one.

Is "minimal escaping" safe?

Yes. It escapes only the characters that genuinely break parsing (# starts a fragment, < > end tags, a double quote truncates the CSS string) and swaps double quotes for single ones. Chrome, Firefox and Safari all render it; keep it off for very old browsers.

Is there a length limit for Data URIs in CSS?

Browsers impose no hard limit on url(), but some build tools, email CSS preprocessors and legacy IE (32 KB) do. A few-kilobyte icon is fine; a tens-of-kilobytes image is still better served as its own file.

Why does a pasted Data URL fail?

The tool decodes it first. If the decoded payload has no svg opening or closing tag the Data URL was truncated or was never an SVG — you will see "Not a valid SVG".

Which encoding does the preview use?

The Base64 form, because it is the most universally accepted. The browser renders it directly with no network request and the markup never leaves your machine.

Keywords:svg2datauridata:image/svg+xmlsvg base64 data uri

Related tools