SVG to CSS Converter

Convert an SVG into a CSS background-image you can paste straight into a stylesheet. The SVG is optimized, then URL-encoded — usually smaller and more compressible than Base64 — and both versions are shown with their sizes and a live preview. Choose single or double quotes, and drop in a file or paste the markup. It's free, runs in your browser, and nothing is uploaded.

Characters escaped in URL-encoded SVG

CharacterBecomes
"' (swapped)
#%23
%%25
<%3C
>%3E
{ }%7B %7D

When to use it

  1. Use an icon as a CSS background without an extra file.
  2. Add a custom checkbox tick or select arrow in pure CSS.
  3. Embed a decorative pattern or divider in a stylesheet.
  4. Shrink an existing Base64 SVG data URI.

How to Use

  1. Paste SVG markup or drop an .svg file.
  2. Keep optimization on and pick a quote style.
  3. Check the preview and the size comparison.
  4. Copy the URL-encoded CSS.

Features

  1. Minimal URL-encoding
  2. Base64 alternative
  3. SVG optimization
  4. Quote style choice
  5. Size comparison and preview
  6. 100% client-side

FAQs

Base64 or URL-encoded SVG?

URL-encoded, in most cases. It's smaller and compresses better; Base64 is only needed for very old tools.

Why does my SVG data URI not show?

Usually an unescaped # (in a color) or a double quote clashing with the url() quotes. This tool escapes both.

Can I change the icon's color with CSS?

Not as a background-image. Use it as mask-image with background-color: currentColor instead.

Should I optimize the SVG first?

Yes. Editors add comments and metadata that cost bytes in every CSS file that uses the icon.

Is my SVG uploaded?

No. Conversion happens in your browser.

Technical Details

An SVG can be used in CSS as a data URI in two ways. Base64 always works but grows the markup by a third and compresses poorly. URL-encoding is usually smaller: whitespace is collapsed, double quotes are swapped for single quotes, and only the characters that would otherwise break the URL — %, #, <, >, { and } — are percent-escaped, leaving the rest readable. The converter does that minimal encoding rather than encodeURIComponent, which escapes far more than necessary. Before encoding it can optimize the SVG with the site's own optimizer, removing comments, editor metadata and excess precision. The output is wrapped in url() with your choice of quote character, and any of that character inside the data is escaped so the rule stays valid. A preview renders the result as a background, and both sizes are compared. For icons that should take the text color, the page notes the mask-image technique.

Developer Tools

Developer Tools

  • CSS Data URI Converter
  • Basic Auth Header Generator
  • Hex Dump Viewer
  • Text Encoding Inspector
  • Punycode Converter
  • Email Obfuscator
  • UUID Validator
  • ULID Generator