SVG to CSS Data URI

Convert SVG markup into an optimized CSS data URI — URL-encoded or base64, minified, with live preview and size readout.

Tool input is processed locally in your browser and is not submitted to CodeNimbleTools. Avoid pasting production secrets into any device or website you do not fully trust.

CSS output

    Preview
    

About this tool

Inlining small SVGs as CSS data URIs kills an HTTP request per icon and keeps styling self-contained. This converter minifies your SVG and encodes it correctly — URL-encoding (smaller and debuggable) or base64 — wrapped in a ready-to-paste background-image rule.

A checkered live preview shows the result, and a byte counter helps you keep URIs sensible.

How to use it

  1. Paste your SVG markup (a missing xmlns is added automatically).
  2. Choose URL-encoding (recommended) or base64, and your quote style.
  3. Copy the generated CSS class.
  4. Check the preview and size readout before shipping.

Useful ways to apply it

  • Inlining UI icons without an icon font or sprite sheet.
  • Custom list bullets and form control graphics in pure CSS.
  • Email-safe decorative graphics where external images are blocked.
  • Eliminating tiny-image HTTP requests on performance-critical pages.

Worked example

Example input

<svg xmlns="http://www.w3.org/2000/svg"><circle cx="5" cy="5" r="4"/></svg>

Expected output

url("data:image/svg+xml,...")

Edge cases to check

  • Quotes, hashes, whitespace and non-ASCII text need correct encoding.
  • Untrusted SVG can contain active or external content depending on how it is embedded.
  • Very large data URIs hurt readability and caching.

Known limitations

Use trusted SVG input and test the generated URI in the exact CSS context where it will be deployed.

How this tool was reviewed

Reviewed with quotes, hashes, whitespace and xmlns handling.

Last reviewed: September 3, 2026 · Maintainer: William

Standards and technical references

Frequently asked questions

URL-encoding or base64 — which is better?
URL-encoding is often compact and remains readable in developer tools, while base64 can be useful for other payload shapes. Compare both with the tool’s byte readout instead of assuming one format is always smaller.
Why does my SVG need xmlns?
Data-URI SVGs are parsed as standalone XML documents; without the namespace declaration browsers render nothing. The tool injects it if missing.
Is there a size limit?
There is no single portable size limit that is safe to promise across every browser and use case. Data URIs are best for small assets; compare payload size, caching behavior and rendering performance before embedding larger SVGs.

Privacy

Tool input is processed locally in your browser and is not submitted to CodeNimbleTools. Avoid pasting production secrets into any device or website you do not fully trust.