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

Drop your SVG here, or click to browse Or paste SVG code anywhere on the page. Nothing is uploaded.
No file?

2Adjust the options

3Preview and download

Live preview
sample.svg
Input and output codeView, edit and copy the code
Input SVG code
Output

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.

  1. Minify first (optional)

    Comments, metadata and whitespace are removed so the data URI is as short as possible.

    Minify pass
  2. data:image/svg+xml,%3Csvg …data:image/svg+xml,<svg …

    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 · tidy
  3. background-image: url("data:image…

    Choose the form

    Switch between URL-encoded and Base64, and wrap the result as raw text, a CSS rule or an <img> tag.

    Raw · CSS · img
  4. SVGURL-encodedBase64

    Compare the sizes

    A chart shows how the URL-encoded and Base64 forms compare to the original SVG.

    Size comparison
The four stages of the SVG to Data URI Converter, from your input to the finished file.

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.

  1. Add your SVG

    Drop a file, paste code or press the sample button.

    Tip: The sample is a small icon.

    Drop SVG
  2. Pick the encoding

    Keep URL-encoded for the smallest result, or switch to Base64 if a tool requires it.

    Tip: Both show their size.

    EncodingWrapperMinify
  3. Choose the wrapper

    Raw, CSS rule or <img> tag.

    Tip: The output is ready to paste.

  4. Copy the result

    Press Copy code, or Download as a text file.

    Tip: Copying from the preview gives the full output.

    Download SVGsvg-to-data-uri.svg

Use the SVG to Data URI Converter

Reference

SVG to Data URI Converter settings / conversion chart

The table compares the encodings. The chart shows relative sizes.

Relative size by encoding

Relative size by encodingSVG source: 1×; URL-encoded: 1.2×; Base64: 1.33×.SVG source1×URL-encoded1.2×Base641.33×
Base64 adds about a third; URL-encoded is usually smaller.

At a glance

  • Largest: Base64.
  • Smallest: SVG source.

Base64 adds about a third; URL-encoded is usually smaller.

SVG to Data URI Converter encodings compared
EncodingTypical sizeReadableBest for
URL-encodedClose to the SVGMostlyCSS and HTML
Base64About 33% largerNoTools that require Base64
Minified firstSmaller inputMostlyBoth

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.

Ready to try it?

Your result is one drop away.

Open the SVG to Data URI Converter

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.