Skip to content

SVG to CSS url()

Paste an SVG and get a data URI for background-image — compact URL-encoding that’s smaller than base64, plus copy-ready CSS and HTML.

SVG code

Paste SVG code above, or open an .svg file.

Preview as a CSS background

Your SVG shows here

Ready to copy

Paste into background-image, mask-image, list-style-image or content.
A complete declaration, ready for your stylesheet.
The same image inline in HTML, no extra request.
For JavaScript, JSON or anywhere that wants the bare URI.

Why URL-encode instead of base64?

SVG is text, so it can sit in a data URI almost as-is: only a few characters (like #, < and %) need escaping. That’s usually around a third smaller than base64, stays readable, and compresses better with gzip. Base64 is there for tools that insist on it.

Good to know

  • Comments, line breaks and extra spaces are removed, and a missing xmlns is added — browsers need it in data URIs.
  • Want a file instead? SVG Code to File downloads it as SVG, PNG, JPG or WebP.

Frequently asked questions

What is an SVG data URI?

A way to put an SVG straight into CSS, for example as a background-image, without a separate file: url("data:image/svg+xml,…").

Why URL-encode instead of base64?

SVG is text, so only a few characters (such as #, < and %) need escaping. That is usually about a third smaller than base64, stays readable and compresses better with gzip. Base64 is available for tools that require it.

What does Squozi change in my SVG?

Comments, line breaks and extra spaces are removed, and a missing xmlns attribute is added, because browsers need it in data URIs.

Is my SVG uploaded?

No. The conversion happens in your browser.

I need a file, not CSS. What should I use?

SVG Code to File downloads SVG code as an .svg, PNG, JPG or WebP file.

Related tools

Squozi SVG to CSS Data URI Encoder — free, online, no sign-up

With Squozi's free SVG to CSS Data URI Encoder you can encode SVG as a CSS data URI to paste into url() in your stylesheet. Squozi also compresses videos, converts video and audio and turns MP4 into MP3. Everything works in any browser on a phone or computer: free, with no sign-up, no watermark and nothing to install, and uploaded files are deleted after 2 hours.