Skip to content
ToolPlankDEV
Image & SVG Tools
100% In-Browser Execution

Updated:

SVG to Data URI Converter

Paste SVG and get a data URI as you type. This svg to data uri converter cleans the SVG, picks the smaller of URL-encoded and Base64, writes ready snippets for CSS, img, mask, React and Tailwind, compares sizes and warns about currentColor. Paste a data URI and it decodes it. Nothing is uploaded.

Options:

SVG or data URI

Input
0 chars · 0 lines

Result

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Preview of your SVG

A preview of the SVG appears here. Scripts and event handlers are never run.

Sizes and checks

Sizes, what was cleaned up and warnings such as currentColor appear here once there is a result.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use SVG to Data URI

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your SVG

    Paste the SVG code into the left box, press Paste, or open an .svg file. The preview shows the image as you type. Example loads a check icon, and Icon with currentColor, Inkscape export and Decode a CSS data URI load other cases.

  2. 02

    Pick the output

    Choose a CSS background-image, the data URI alone, an img tag, a mask-image, a React style or a Tailwind class. Smart encoding uses whichever of URL-encoded and Base64 is shorter, and you can force either one.

  3. 03

    Read the sizes and warnings

    The panel under the result compares the original SVG, the cleaned SVG and both data URI forms in bytes, and warns about currentColor, scripts, outside links and a missing size.

  4. 04

    Copy the snippet

    Press Copy and paste the line into your stylesheet, HTML, component or Tailwind class list. To go back, paste a data URI or a CSS line that contains one and the SVG comes out.

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
<?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:

CSS
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 &amp; 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.

Frequently Asked Questions

Technical Q&A for SVG to Data URI

Common questions about edge cases, character encoding, and privacy guarantees.

Paste the SVG into the left box and the data URI appears on the right, wrapped in the snippet you choose. Press Copy to use it.

URL-encoded is usually shorter and stays readable, because SVG is already text. Base64 is always about a third larger than the bytes. Smart mode picks the shorter one for your file.

Choose CSS background-image, copy the line and paste it into a rule. Add background-repeat, background-size and background-position as you need.

The SVG uses currentColor, which cannot see the page's text color when the SVG is used as an image. Use a fixed color, or the mask-image output with a background color.

Browsers only draw an SVG as an image when it declares the SVG namespace. The tool adds xmlns="http://www.w3.org/2000/svg" when it is missing and tells you.

Choose Tailwind class and paste the result into your class list. It uses the form bg-[url('...')] with every special character escaped.

Yes. Paste a data:image/svg+xml URI, or a CSS or HTML line that contains one, and the SVG appears. Both URL-encoded and Base64 forms work.

No. Cleanup removes comments, metadata, editor data and extra whitespace, not shapes, paths or styles. Turn it off to encode the SVG exactly as pasted.

No. The conversion runs in your browser and nothing is sent to a server.