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
- Paste <svg> markup, open an .svg file, or pick a sample icon.
- Check the preview; switch to the dark background for icons drawn in light colours.
- 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?
Can I use SVG Data URIs directly in CSS?
Why do unescaped '#' characters break SVG data URIs?
Is there a size limit for data URIs?
Page last updated . Found a wrong result or a mistake on this page? Let us know.
Related tools
Regex Builder
Build a regular expression from blocks, with live matches.
SQL Formatter
Put each SQL clause on its own line, or minify to one line.
JSON to YAML Converter
Convert JSON to YAML and back, with clear error locations.
Chmod Permissions Calculator
Work out chmod values from checkboxes, octal or ls -l strings.