SVG to data URI converter

An SVG data URI puts the SVG file inside a URL (data:image/svg+xml,...) so CSS or HTML can use it without a separate file request. Paste your SVG below to get the URL-encoded version, a ready background-image rule and a base64 version.

How to use the converter

  1. Paste the SVG code into the box, or keep the default icon to try it first.
  2. Check the preview on the checkerboard to confirm the SVG renders correctly.
  3. Copy the format you need: the URL-encoded data URI, the CSS background-image rule or the base64 version.

Preview

SVG preview

URL-encoded data URI

193 characters

data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='%23111111' d='M12 2 2 22h20L12 2Zm0 4.5 6.5 13h-13L12 6.5Z'/%3E%3C/svg%3E

CSS background-image

219 characters

background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='%23111111' d='M12 2 2 22h20L12 2Zm0 4.5 6.5 13h-13L12 6.5Z'/%3E%3C/svg%3E");

Base64 data URI

242 characters

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ij48cGF0aCBmaWxsPSIjMTExMTExIiBkPSJNMTIgMiAyIDIyaDIwTDEyIDJabTAgNC41IDYuNSAxM2gtMTNMMTIgNi41WiIvPjwvc3ZnPg==

URL-encoded vs base64 SVG data URI

URL-encoding is the better default for SVG because it stays readable and is usually smaller, while base64 is the fallback for tools that reject special characters.

FormatExample prefixSizeBest for
URL-encodeddata:image/svg+xml,%3Csvg...Usually smaller for SVGCSS backgrounds and icons
Base64data:image/svg+xml;base64,PHN2Zy...About 33% largerTools or systems that reject special characters
Separate .svg fileurl(icon.svg)Cached on its ownLarge or reused images

Frequently asked questions

Why is URL-encoding better than base64 for SVG?

URL-encoding keeps the SVG readable and usually makes a smaller data URI, because only a few characters such as <, >, # and % need escaping. Base64 turns every byte into four characters, so the same SVG grows by about a third. Use URL-encoding for CSS backgrounds and icons unless a tool rejects the special characters.

Do I need xmlns in the SVG?

Yes. A browser will not render an SVG inside a data URI without xmlns="http://www.w3.org/2000/svg" on the root element. This converter checks the root <svg> tag and adds the namespace automatically when it is missing, so the preview and the copied data URI both work.

Can I change the colour of an SVG data URI with CSS?

No. CSS color and fill do not reach inside an image loaded through background-image, so the SVG keeps the colours it was encoded with. Edit the fill in the SVG before you encode it, or use the SVG as a mask-image and set the colour with background-color.

Is my SVG uploaded?

No. The converter runs entirely in your browser, so the SVG code never leaves your device and nothing is stored on a server. You can use it on private icons and client work without uploading a file.

When should I not inline an SVG?

Skip the data URI for large or repeated images. A separate .svg file is cached on its own, so the browser downloads it once and reuses it across pages, while an inlined data URI is re-sent with every stylesheet or HTML response that contains it.

Related

More image & SVG tools

Color tools

Image tools

CSS generators

Typography & units

More free tools

All free tools