Skip to content
TabBench

SVG to Data URI Converter

Convert SVG code into optimized UTF-8 and Base64 Data URIs for CSS background-image and HTML img tags.

Runs in your browser. Nothing you add is uploaded.

What the SVG to Data URI Converter does

Paste SVG markup or open an .svg file, and this tool cleans it (removing the XML declaration, DOCTYPE, comments and whitespace between tags) and gives you five ready-to-paste forms: a CSS background-image rule, a URL-encoded data URI, a Base64 data URI, an HTML <img> tag, and a JSX version with attributes renamed for React. A live preview on a light or dark background confirms the encoded version still renders.

How to turn an SVG into a data URI

  1. Paste <svg> markup, open an .svg file, or pick a sample icon.
  2. Check the preview; switch to the dark background for icons drawn in light colours.
  3. Copy the form you need: CSS background-image, URL-encoded data URI, Base64 data URI, <img> tag or JSX.

The SVG to Data URI Converter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.

When to use it

Icons inside CSS

Custom select arrows, checkbox ticks and list bullets are often drawn with background-image so that no extra file is requested. The URL-encoded form keeps the markup mostly readable inside your stylesheet, which makes it easy to change a fill colour later.

Single-file pages

A self-contained HTML report or an offline page cannot fetch images from a server. Embedding small SVGs as data URIs keeps everything in one file. For email, use PNG instead: many email clients, Gmail included, do not display SVG at all.

Moving an icon into React

SVG exported from design tools uses attributes such as stroke-width, fill-rule and class, which React expects as strokeWidth, fillRule and className. The JSX output renames the common ones and turns inline style strings into style objects, saving a round of fixes by hand.

Good to know

  • In the URL-encoded form, # must become %23, or the browser treats everything after it as a page fragment and colours like #fff break. The encoder also escapes %, <, >, { and }.
  • Double quotes are switched to single quotes so the result can sit inside a double-quoted url("…"). If your SVG already uses single quotes inside attribute values, such as a font-family list, check the preview.
  • Base64 makes the data about a third larger than the raw markup. URL-encoding usually adds less, and it compresses better with gzip or Brotli, so it is normally the better choice for SVG.
  • Give the SVG a viewBox so it scales to the size you set in CSS with background-size or width and height.
  • A data URI is cached only as part of the file that contains it, so keep inlining for small icons and serve larger graphics as separate files.

Frequently asked questions

Why use UTF-8 Data URIs instead of Base64 for SVG?

Base64 adds roughly 33% bloat to ASCII text files. Because SVGs are plain XML text, UTF-8 percent-encoding only escapes necessary characters (like '#' and '"'), producing significantly smaller payloads that gzip better.

Can I use SVG Data URIs directly in CSS?

Yes. Paste the generated CSS snippet directly into your stylesheet: background-image: url('data:image/svg+xml,...'); to render icons without extra HTTP requests.

Why do unescaped '#' characters break SVG data URIs?

In a URL, # starts the fragment identifier, so the browser stops reading the image data at the first unescaped # and the SVG is cut short. Escaping it as %23 keeps colours like fill="#ff0000" intact.

Is there a size limit for data URIs?

Current browsers accept very long data URIs, but every byte is downloaded again with each stylesheet or page that embeds it and cannot be cached on its own. Inlining pays off for icons of a few kilobytes; larger graphics are better as files.

Page last updated . Found a wrong result or a mistake on this page? Let us know.