SVG to CSS
Turn SVG into CSS you can actually ship (pick an .svg file or paste the markup): a background image, a mask rule with the -webkit- prefix, or a :root variable referenced through var(), with editable selector and size plus the real data URI / CSS lengths and a browser-rendered preview.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
The .svg file is read as UTF-8 text and the CSS is generated in your browser — nothing is uploaded.
Pick a file or paste markup and the generated data URI renders the icon here.
Generated CSS and real statistics
Lengths and rule count are measured on the generated CSS; the download is a real .css file.
Pick a file or paste markup and the generated CSS shows up here.
What this tool does
- Ship a brand icon inside your stylesheet: paste the markup in Background mode and get a .icon { background-image: url("data:…") } rule ready to paste.
- Recolour an icon without editing the SVG: use Mask mode, treat the SVG as a mask and let background-color do the tinting.
- Reuse the same icon in many places: the :root variable mode writes the Data URI once and every other rule references var(--svg-icon).
- The URL-encoded variant stays readable — you can see the fill attribute — which makes theme switching with CSS variables far easier to debug.
Example
Input
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><rect width="24" height="24" fill="#0ea5e9"/></svg>
Output
.icon {
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cmVjdCB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIGZpbGw9IiMwZWE1ZTkiLz48L3N2Zz4=");
background-size: contain;
background-repeat: no-repeat;
}Background is the default mode. The stats show 134 SVG bytes, a 206-character Data URI, 304 characters of CSS, 1 rule, plus the real lengths of both data URI forms (Base64 206 / percent-encoded 257). Choosing an .svg file works too (read as UTF-8 source) and the download is a real .css file.
Frequently asked questions
Why use a mask instead of a background to recolour an icon?
A background image keeps the colours baked into the SVG, so recolouring means editing the SVG or adding a filter. A mask uses the SVG alpha as a stencil and the element background-color as the paint, so one SVG can serve any colour, including hover states and CSS variables.
Does the mask need the -webkit- prefix?
Yes. Safari and older Chromium only understand -webkit-mask-image / -webkit-mask-size, so the tool emits both the prefixed and the standard declaration with identical values.
What is the advantage of the :root variable mode?
Data URIs are long; repeating them bloats the stylesheet and makes maintenance painful. Hoisting one into a :root variable and referencing var(--svg-icon) means changing the icon in a single place. The trade-off is that it requires CSS custom property support.
What are the selector and variable limits?
Selectors accept only .class or #id (so the tool can never emit a syntactically broken rule), and variable names must start with -- and use only letters, digits, - and _. Anything else fails loudly instead of producing broken CSS.
What goes in the size field?
contain by default, which scales the icon to fit the box. cover, 100% 100% and 24px 24px are all valid and are written verbatim into background-size / mask-size.
Keywords:svg2csssvg background-imagemask-image svgdata uri css