CompleteSEOTools
Home › Image & Design Tools › SVG to Data URI Converter

SVG to data URI converter

Paste SVG markup and get a small data URI you can drop into CSS or an img tag.

About SVG to Data URI Converter

An SVG is already text, so it can go into a data URI without Base64. Encoding only the few characters that need it gives a shorter result than Base64. This tool does that, swaps double quotes for single ones so the value fits inside url() and src, adds the missing xmlns attribute if you forgot it, and also builds the Base64 form so you can compare sizes. Nothing leaves your browser.

  • Using an icon as a CSS background without an extra request.
  • Keeping a small logo inside a single HTML file.
  • Choosing between the URL-encoded and Base64 forms by actual size.
  • Fixing an SVG that will not show because the xmlns attribute is missing.

How to use SVG to Data URI Converter

1

Step 1

Paste your SVG code into the box or choose an .svg file.

2

Step 2

Read the sizes in the table and pick the form you want.

3

Step 3

Copy the URI, the CSS rule or the img tag.

Good to know

  • Line breaks become spaces and the gaps between tags are removed. Other spaces are kept.
  • Scripts inside an SVG do not run when it is used as an image, whichever form you choose.
  • For large SVGs a normal file link is better, because a data URI cannot be cached on its own.

Common questions

Is URL-encoded better than Base64?

For SVG it is usually shorter, because Base64 grows the text by a third and URL encoding only changes a few characters.

Why are the quotes changed?

A data URI sits inside quotes in your CSS or HTML. Single quotes inside it avoid clashing with the outer double quotes.

Does it clean or optimise the SVG?

No. It only trims line breaks and spaces between tags. Use an SVG optimiser first if you want smaller paths.