SVG to CSS Data URI Converter

Paste an SVG and get a compact, URL-encoded data URI plus ready-made background-image and recolourable mask-image CSS.

Runs in your browser
Encoding
Open .svg
CSS output
Data URI
background-image
mask-image (recolourable icon)

background-image preview

mask-image preview

Your data never leaves your computer. All processing happens 100% locally in your browser.

How to use the SVG to CSS Converter

  1. Paste your SVG code, open an .svg file or load the sample.
  2. Keep Clean up SVG on to strip comments, metadata and editor attributes, and choose URL-encoded or Base64.
  3. Check both previews — the normal background image and the single-colour mask version.
  4. Copy the data URI or the complete CSS rule and paste it into your stylesheet.

What is an SVG data URI?

A data URI embeds a file directly in your CSS instead of linking to it: background-image: url("data:image/svg+xml,…"). For small icons, dividers, patterns and custom checkboxes this saves an HTTP request, avoids a flash of missing images and keeps the asset next to the styles that use it.

URL-encoding vs Base64

SVG is text, so it doesn’t need Base64. Base64 inflates any file by about 33% and turns it into an unreadable blob that compresses poorly with gzip or Brotli. A URL-encoded SVG stays close to its original size and readable. Only a few characters must be escaped:

CharacterEncodedWhy
#%23Otherwise starts a URL fragment — colours like #fff break the image.
%%25The escape character itself.
< >%3C %3ERecommended for compatibility with strict parsers.
"' or %22Attribute quotes are switched to single quotes so the CSS can wrap the URI in double quotes.

Use Base64 only when a tool or framework rejects anything else. The size cards under the preview show both results so you can compare.

Recolourable icons with mask-image

An SVG used as a background image is rendered in isolation: CSS on the page can’t change its fills, and currentColor inside it won’t follow your text colour. The mask-image snippet solves this by using the SVG only as a stencil and painting it with background-color: currentColor, so one icon works in any colour, hover state or dark mode. The -webkit-mask line is still needed for some browsers.

Cleanup and limits

Cleanup removes the XML declaration, comments, <metadata>, <title> (meaningless in a background), Inkscape/Sodipodi/Sketch attributes and extra whitespace, and adds the required xmlns if it’s missing — without it the browser won’t render the image. Embed only small SVGs (a few KB): large data URIs bloat every CSS download and can’t be cached separately. For complex graphics, link the file instead. Need a React component rather than CSS? Use SVG to JSX; for raster images, see Image to Base64.

Using it in Webflow

Webflow’s Backgrounds panel expects an uploaded image, so paste the generated rule into a <style> tag in an Embed element or in the page/site custom code, and give your element the matching class (e.g. icon).

Tools that pair well with the SVG to CSS Converter

  • CSS Minifier — Paste a stylesheet to shrink it instantly.
  • CSS Gradient Generator — Design a gradient visually — drag colour stops, change the angle or type, start from a preset — and copy production-ready CSS with a solid fallback colour.
  • Box Shadow Generator — Stack multiple shadow layers, tweak offsets, blur, spread and opacity on a live card, then copy the box-shadow or text-shadow CSS.
  • Clamp Calculator — Enter a minimum and maximum size and the viewport range — get a zoom-friendly clamp() value with the maths explained, a live preview and a complete fluid type or space scale.

Frequently asked questions

Why isn’t my SVG data URI showing up?
The usual causes are an unescaped # (in colours like #fff), a missing xmlns="http://www.w3.org/2000/svg" attribute, or unbalanced quotes between the CSS url("…") and the SVG attributes. This tool fixes all three.
Is URL-encoding or Base64 better for SVG in CSS?
URL-encoding is usually better: the result is smaller, readable and compresses well. Base64 adds about a third to the size and is only worth it when a toolchain requires it.
Can I change the colour of an SVG background image with CSS?
Not directly — CSS can’t reach inside a background image. Either edit the fill in the SVG before encoding, or use the mask-image snippet and set background-color, which you can change on hover or in dark mode.
Do I need to include charset=utf-8 in the data URI?
No. Non-ASCII characters are percent-encoded as UTF-8, which browsers decode correctly for SVG, so data:image/svg+xml, is enough.
Is there a size limit for data URIs in CSS?
Browsers handle very large data URIs, but they bloat your stylesheet and can’t be cached separately. Keep embedded SVGs to a few kilobytes and link larger files.

Related tools