Turn an SVG into a URL-encoded data URI ready for a CSS background, or decode one back into markup, with the size of each encoding shown.
Waiting for an SVG
Sanitised first, then encoded. URL encoding is usually smaller and far more readable than base64.
Nothing to preview yet.
The result appears here.The URI is wrapped in single quotes because an SVG commonly contains double ones, and every # is escaped as %23 — an unescaped hash starts a fragment and silently truncates the image at the first hex colour, which is why a hand-written data URI so often works locally and breaks in production.
SVG to Data URI Converter runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
An SVG as a data URI goes straight into a CSS `background-image` with no network request, which is the right trade for small decorative things — a chevron, a checkbox tick, a pattern — where a separate request would cost more than the bytes.
URL-encoding beats base64 for SVG, which surprises people who reach for base64 by habit. SVG is text, and base64 inflates text by about a third before gzip. URL-encoding only escapes the characters that would break the CSS, so the result is typically 25–30% smaller than the base64 equivalent and, as a bonus, stays readable — you can see what the image is in the stylesheet. Both are produced here with their sizes, so the comparison is in front of you rather than taken on trust.
The practical gotchas are all about quoting. The `#` in a hex colour must be escaped or everything after it is treated as a fragment; double quotes inside the SVG have to either be escaped or swapped for single quotes to survive the CSS string; and a newline inside the URI is not allowed. The encoder handles all three, which is why hand-escaping an SVG usually ends in a background that silently does not appear.
Decoding works the other way, for when you have inherited a stylesheet full of opaque data URIs and need to know what they are. Both directions run entirely in your browser; nothing is uploaded.
URL-encoding, nearly always. SVG is text and base64 inflates text by roughly a third, while URL-encoding escapes only the characters CSS would choke on. The result is typically 25–30% smaller and still readable in the stylesheet.
Usually an unescaped # from a hex colour, which CSS reads as the start of a fragment and discards everything after. Unescaped double quotes inside a double-quoted CSS string and a literal newline in the URI are the other two usual causes.
For anything large or reused. A data URI cannot be cached separately, so the same image inlined in ten places is downloaded ten times as part of your CSS, and a large one delays the stylesheet that the page is blocked on. Small and decorative is where it pays.
Yes, and it works the same way. The difference is that an SVG in an img is isolated — no script runs, and external resources are not loaded — whereas an inline SVG in the DOM is part of your document.
Encoding does not alter the markup; it encodes what you give it. If the source is untrusted, run it through the SVG optimizer first, which sanitises by allowlist, and encode the result.