SVG to Data URI

Paste SVG markup and get an inline data: URI plus the CSS, mask, img or JSX snippet to paste. Nothing is uploaded — it all runs in your browser.

Try:
Snippet

About this tool

SVG to Data URI turns inline SVG markup into a data:image/svg+xml,... URI you can paste into CSS, HTML, JSX, or design-system tokens. The default output is the URL-encoded form because SVG is text: keeping readable markup and escaping only the unsafe characters is usually shorter than Base64. Pick Base64 when a downstream tool keeps rewriting or reformatting the URI.

The converter is SVG-aware rather than a generic byte encoder. It can minify the markup first, rewrite double quotes to single quotes for shorter quoted url("...") snippets, and add the missing root xmlns="http://www.w3.org/2000/svg" attribute that often makes SVG data URIs render blank in CSS.

Everything runs locally in your browser. Your icon, logo, or pattern SVG is not uploaded.

Example

Input:

<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="7" fill="#0af"/></svg>

With Snippet set to CSS background-image, the output starts like:

background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E...");

Options

Limits and edge cases

FAQ

Should I choose URL-encoded SVG or Base64?

Choose URL-encoded unless you have a specific compatibility problem. SVG is text, so escaping only the unsafe characters usually produces a shorter and more readable URI than Base64, which adds about one third to the payload size. Use the Size comparison output when you want to confirm the exact winner for one SVG.

Why does the tool add an xmlns attribute?

Browsers often require the root SVG namespace when an SVG is loaded from a data: URI, especially in CSS background-image and mask-image. An ordinary inline <svg> can appear to work without it, then render blank when encoded. Leaving Add xmlns when missing on prevents that failure.

Can I use the result in CSS masks?

Yes. Set Snippet to CSS mask-image and the tool emits both -webkit-mask-image and the standard mask-image declaration. That covers Safari/WebKit as well as browsers that support the unprefixed property.

Will minify change my drawing?

For icon-style SVGs, no: it removes declarations, comments, and redundant whitespace that do not change rendering. Turn minification off if your SVG includes <text> nodes where repeated spaces are meaningful, or if you need the encoded markup to match the original bytes exactly.

Is this the same as a generic data URI encoder?

No. A generic encoder can wrap any bytes in a data: URI. This tool is specialized for SVG: it uses the SVG MIME type, adds the namespace when needed, can minify markup first, offers CSS/HTML/JSX snippet shapes, and compares URL encoding against Base64 for the same SVG.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool svg-to-data-uri '<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="7" fill="#0af"/></svg>'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/svg-to-data-uri/?svg=%3Csvg%20viewBox%3D%220%200%2016%2016%22%3E%3Ccircle%20cx%3D%228%22%20cy%3D%228%22%20r%3D%227%22%20fill%3D%22%230af%22%2F%3E%3C%2Fsvg%3E&encoding=url&output=uri&quotes=single&minify=true&add_xmlns=true

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.