Browser support
CSS helpers
Clean-up before encoding
Removes the XML declaration, doctype, comments, Inkscape, Sodipodi and Sketch metadata, and empty defs. Shapes, ids and styles are left alone.
Replace colors
Hex or currentColor values in fill, stroke and stop-color show up here once you paste an SVG.
How to use
Add your SVG
Paste the full <svg> markup, click Upload .svg, or drop a file on the input box. Files up to 1 MB are accepted. Sample loads a small checkmark icon to try.
Clean up and pick a format
Leave Optimize on, change any color under Replace colors, then choose Modern (URL-encoded) or Legacy (base64) and one of the seven CSS helpers, such as Recolorable icon.
Check and copy
Check the preview as Contain or Tile on a light, dark or checker backdrop, then Copy CSS or download it. To reverse a data URI, open the Data URI to SVG tab.
Why SVG to CSS Converter
- Paste, upload or drag and drop an SVG; everything runs in your browser.
- Optimize and recolor before encoding, with the bytes saved.
- Seven formats, including a mask-image icon that takes the text color.
- Decode any SVG data URI back into code, and download .css or .svg files.
URL-encoded vs base64 SVG data URIs
Both formats embed the same SVG. The difference is how the text is escaped. The sizes below are for the tool's sample checkmark icon, which is 252 bytes after whitespace is collapsed.
In the Modern output, double quotes are swapped for single quotes and characters such as <, >, # and % are percent-encoded. If the SVG already contains single quotes, double quotes are encoded as %22 instead so attributes stay intact. Gzip on your server shrinks both formats further, and URL-encoded text usually compresses better than base64.
| URL-encoded (Modern) | Base64 (Legacy) | |
|---|---|---|
| Starts with | data:image/svg+xml, | data:image/svg+xml;base64, |
| Sample icon size | 291 bytes | 362 bytes |
| Readable in the stylesheet | Yes, tags and attributes stay visible | No |
| Size overhead | A few bytes per escaped character | About one third |
| Browser support | All current browsers | All browsers, including very old ones |
Example: an SVG icon as a list bullet and a background
Load the Sample and choose the CSS bullets helper. The output is a single line you can put on a list: ul.checks { list-style-image: url("data:image/svg+xml,..."); }. Each list item then shows the checkmark instead of a dot. If the icon is too large, lower width and height in the SVG before converting.
For a background, choose Advanced background-image. It writes background-image plus background-repeat: no-repeat, background-position: center center and background-size: cover. For icons inside buttons, change cover to a fixed size such as 16px 16px and add padding so text does not sit on top of the icon.
The Inside class helper wraps the same value in a .svg-bg class with background-size: contain, which fits the whole icon inside any box without cropping.