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
- Paste or upload an SVG. Paste SVG markup or drop an .svg file into the input box.
- 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.
- Preview background vs. mask. Check how the icon renders as a CSS background-image and as a currentColor-tinted mask-image.
- 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
| Method | Output size | Color control | Best for |
|---|---|---|---|
| URL-encoded Data URI | Smallest (often smaller than Base64) | Uses colors inside the SVG | Multi-color icons, patterns, and background-image. |
| Base64 Data URI | ~33% larger than raw SVG | Uses colors inside the SVG | Legacy parsers or environments that strip #, <, or >. |
| CSS mask-image | Same as URL-encoded | Follows background-color / currentColor | Single-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
SVG to JSX ConverterTurn any SVG into a React (JSX/TSX), Angular, Vue or Svelte component with a size prop and currentColor. SVGO cleanup built in; nothing is uploaded.SVG OptimizerCompress SVG files with SVGO 4 in your browser. Before/after size, gzip size and preview, plus batch optimize up to 200 files to a .zip.SVG viewBox CropperTrim empty whitespace around any SVG, center it in a 1:1 square, or normalize it to a 24×24 or 32×32 icon grid in your browser.SVG to PNG, ICO & FaviconExport an SVG as a sharp PNG, WebP or JPG at any size, a multi-size .ico, or a complete favicon set with Apple touch icon, maskable icons and manifest.mat-icon SVG Migration HelperMove Angular Material mat-icon from the icon font to SVG: rewrites templates to svgIcon, downloads only the Material Symbols you use, and writes the MatIconRegistry code.Image to Base64Convert PNG, JPG, SVG, WebP and other images to Base64 or a data URI, ready to paste as an img tag, CSS or Markdown. Nothing is uploaded.
Need an icon to start from? Browse Material Symbols, Lucide, Heroicons, the free CC0 icon packs or this week's new icons.