Skip to content
ToolShedby Wasim Shaikh

SVG to CSS Data URI Converter

Convert any SVG into a compact URL-encoded CSS Data URI or Base64 for background-image, mask-image (currentColor), and CSS variables.

Strips metadata and collapses whitespace before encoding.

How to Use an SVG in CSS

  1. Paste or upload an SVG. Paste SVG markup or drop an .svg file into the input box.
  2. Choose URL-encoded or Base64. Keep URL-encoded (UTF-8) for the smallest CSS output, or switch to Base64 if an older tool requires ASCII.
  3. Preview background vs. mask. Check how the icon renders as a CSS background-image and as a currentColor-tinted mask-image.
  4. Copy the CSS snippet. Pick background-image, mask-image, Raw Data URI, CSS Variable, or HTML <img> and copy it.

URL-Encoded vs. Base64 vs. mask-image

MethodOutput sizeColor controlBest for
URL-encoded Data URISmallest (often smaller than Base64)Uses colors inside the SVGMulti-color icons, patterns, and background-image.
Base64 Data URI~33% larger than raw SVGUses colors inside the SVGLegacy parsers or environments that strip #, <, or >.
CSS mask-imageSame as URL-encodedFollows background-color / currentColorSingle-color UI icons that change color on hover or dark mode.

Frequently Asked Questions

Why is URL-encoded SVG better than Base64 in CSS?
URL-encoding only escapes a few characters (#, %, <, >, {, }) and keeps the rest readable, making it shorter than Base64 and much more compressible with gzip or Brotli.
Why doesn’t currentColor work inside background-image: url(...)?
An SVG loaded through url() is treated as an external image, so CSS text color does not cascade into it. Use the generated mask-image snippet instead to tint monochrome icons with currentColor.
Does it optimize the SVG before encoding?
Yes, by default it runs SVGO 4 in your browser to strip editor metadata and extra whitespace. You can toggle this off anytime.
Is my SVG uploaded anywhere?
No. SVGO, encoding, and the CSS previews all run locally in your browser.

Sources & Standards

Last reviewed .

Related Tools

Need an icon to start from? Browse Material Symbols, Lucide, Heroicons, the free CC0 icon packs or this week's new icons.