SVG to Data URI Converter: Turn SVG into a Compact Data URI
Convert SVG to a compact URL-encoded data URI, or Base64, ready to paste into CSS or HTML.
SVG to Data URI Converter tool
1Add your SVG
2Adjust the options
3Preview and download
Input and output codeView, edit and copy the code
Under the hood
How SVG to Data URI Converter works
An SVG to Data URI converter turns SVG code into a data: URL you can use anywhere a URL is accepted. This one defaults to the compact URL-encoded form rather than Base64.
- SVGMinified
Minify first (optional)
Comments, metadata and whitespace are removed so the data URI is as short as possible.
Minify pass URL-encode the SVG
The SVG is percent-encoded with only the necessary characters escaped. Quotes become single quotes so it fits inside CSS url("…").
encodeURIComponent · tidyChoose the form
Switch between URL-encoded and Base64, and wrap the result as raw text, a CSS rule or an <img> tag.
Raw · CSS · imgCompare the sizes
A chart shows how the URL-encoded and Base64 forms compare to the original SVG.
Size comparison
Why use a data URI
- No extra request
- The image is part of the CSS or HTML, so the browser needs no separate file.
- Compact when URL-encoded
- URL-encoded SVG is usually smaller than Base64 and compresses better with gzip.
- Works in CSS and HTML
- Use it in background-image, img src and many other places.
Step by step
SVG to Data URI Converter process
Four steps convert an SVG to a data URI. Keep Minify on for the shortest result.
Add your SVG
Drop a file, paste code or press the sample button.
Tip: The sample is a small icon.
Pick the encoding
Keep URL-encoded for the smallest result, or switch to Base64 if a tool requires it.
Tip: Both show their size.
Choose the wrapper
Raw, CSS rule or <img> tag.
Tip: The output is ready to paste.
BeforeAfterCopy the result
Press Copy code, or Download as a text file.
Tip: Copying from the preview gives the full output.
Reference
SVG to Data URI Converter settings / conversion chart
The table compares the encodings. The chart shows relative sizes.
Relative size by encoding
At a glance
- Largest: Base64.
- Smallest: SVG source.
Base64 adds about a third; URL-encoded is usually smaller.
| Encoding | Typical size | Readable | Best for |
|---|---|---|---|
| URL-encoded | Close to the SVG | Mostly | CSS and HTML |
| Base64 | About 33% larger | No | Tools that require Base64 |
| Minified first | Smaller input | Mostly | Both |
Answers
SVG to Data URI Converter FAQ
Questions people ask about the SVG to Data URI Converter, answered for this specific use case.
What is a data URI?
A data URI is a URL that contains the file itself, so no separate request is needed.
URL-encoded or Base64?
URL-encoded is usually smaller and compresses better. Use Base64 only if a tool requires it.
Where can I use a data URI?
In CSS background-image, in <img src>, and in any place that accepts a URL.
Why are the quotes single quotes?
So the URI can sit safely inside a double-quoted CSS url() or HTML attribute.
Is my SVG uploaded?
No. Encoding happens in your browser.
All converters
Every free converter and SVG tool
43 free tools that run in your browser. Pick a converter below, or search by format or task.
No converter matches that search. Try “SVG”, “logo” or “PNG”.