How to convert SVG to a data URI
A data URI puts a file inside the address itself, so a stylesheet or a page can show an image without a second request. An SVG is already text, which makes it easy. A svg to data uri converter wraps that text after data:image/svg+xml, and escapes the characters that would break a URL or a CSS string.
Everything runs in your browser. The SVG is not uploaded, as the Privacy Policy explains.
URL-encoded or Base64
There are two ways to write the same data. Base64 turns the bytes into letters and digits and always grows the data by about a third. URL-encoding keeps the SVG as text and only escapes the few characters that need it: percent, the hash sign, angle brackets, quotes, backslashes and anything outside ASCII. SVG is mostly letters and digits, so URL-encoding is usually the shorter one.
The tool measures both for your SVG and, in Smart mode, uses the shorter. URL-encoded also stays readable and compresses better when the stylesheet is gzipped. Choose Base64 when a tool you paste into does not accept raw quotes or percent escapes.
A worked example
This icon has an XML declaration, a comment and no xmlns attribute:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Check icon -->
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#16a34a" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<path d="M8 12.5l3 3 5-6"/>
</svg>The tool removes the declaration and the comment, adds the xmlns attribute that browsers require, switches the double quotes inside to single quotes so the CSS string can use double quotes, and escapes the hash sign in the color as %23:
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2316a34a' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M8 12.5l3 3 5-6'/%3E%3C/svg%3E");CSS, img, mask, React and Tailwind snippets
- CSS background-image: one line to paste into a rule. It sets only the image, so add background-repeat and background-size yourself.
- HTML img tag: the data URI in src, with the ampersand written as & as HTML requires.
- CSS mask-image: the shape of the SVG cuts the element, and the element's own background color fills it. This is the way to color an icon from CSS. Both the standard and the -webkit- lines are written.
- React style: an object property with the URI in a JavaScript string. Every special character is written as a % escape so no quote can end the string early.
- Tailwind class: bg-[url('...')], with the same full escaping so the brackets, parentheses and underscores in the SVG cannot break the class name.
currentColor does not work in an image
Many icon sets use stroke="currentColor" so the icon takes the text color. That only works when the SVG is inline in the page. As a background image or an img source, the SVG is a separate picture that cannot see the page's text color, so currentColor draws black. The tool warns you when it finds it.
What the cleanup removes
With cleanup on, the tool removes the XML declaration, the DOCTYPE, comments, metadata blocks, Inkscape and Sodipodi elements and attributes, and extra whitespace. The picture does not change, and the data URI gets shorter. When the SVG contains text or xml:space="preserve", whitespace is kept so words are not glued together, and script and CDATA blocks are left exactly as written. Quotes inside text and style blocks are not changed. Only the quotes around attribute values are switched to single quotes.
It does not simplify paths or round numbers. For a full optimizer use a dedicated tool first, then paste the result here. Scripts, event handlers and links to other addresses are left in place and reported, because they do not run or load when an SVG is used as an image. To see the markup as plain XML, SVG to XML is nearby.
Decode a data URI back to SVG
Paste a data:image/svg+xml URI, with or without a url() or an img tag around it, and the tool switches to decoding. It handles URL-encoded and Base64 forms and returns the SVG text, ready to edit. If the input holds several data URIs, the first is decoded and the notes say so.
For other images use Image to Base64 and Base64 to Image, and SVG to PNG to make a raster copy.