SVG to Data URL Converter

Paste raw SVG markup and turn it into a URL-encoded data URL for CSS, HTML, or inline browser tooling. The preview updates locally and never uploads your SVG anywhere.

Use the sample if you want to see the output shape first.

Source bytes
0
Output bytes
0
Reduction
0%
Data URL

        
CSS background-image

        
Preview
SVG preview
About this tool

SVG to Data URL Converter

SVG to Data URL converts raw SVG markup into a URL-encoded data URL plus a ready-to-paste CSS background-image rule, with options to strip XML declarations and comments and collapse whitespace.

How to use it

  1. Paste your SVG markup, or load the sample.
  2. Turn on the cleanup options to shrink the output.
  3. Press Convert and copy the data URL or the CSS rule.

Why SVG should be URL-encoded rather than Base64

SVG is text, not binary, so Base64 encoding it is wasteful: it adds a third to the size for no benefit. URL encoding only escapes the handful of characters that would break the CSS, leaving the rest readable.

A URL-encoded SVG data URL is typically smaller than the Base64 equivalent and stays human-readable, so you can spot a problem in the markup without decoding it. This is why the CSS community settled on URL encoding for inline SVG.

When it helps

  • Inlining an icon as a CSS background without a separate file.
  • Embedding a custom bullet, chevron or checkbox in a stylesheet.
  • Shipping an SVG inside a single-file page.
  • Avoiding a network request for a small vector asset.

Common mistakes

  • Base64-encoding SVG out of habit. URL encoding is smaller and clearer for text formats.
  • Leaving the XML declaration in. It is unnecessary in a data URL and adds bytes to every use.
  • Forgetting to encode the hash character in fill colours, which terminates the URL early and breaks the rule.
SVG to Data URL Converter interface preview
Screenshot of the live SVG to Data URL Converter interface.