Developer tools

SVG to CSS

Encode an SVG as a CSS background or mask data URL.

SVG to CSS
Esc to restore

Your inputs

Up to 200,000 characters. Source is processed locally and never executed.

Results update as you type. Larger files run when you press Update result.

Your result

Your result will appear here.

More actions

Your inputs stay in this browser. Nothing is uploaded or saved.

A clear answer. Here’s how.

Percent-encodes the SVG as UTF-8 inside a quoted image/svg+xml data URL, including #, quotes, percent signs, parentheses and line breaks. Produces a single class rule with background-image or mask-image. Mask mode adds currentColor and mask sizing; set width and height in your own CSS. Source is never rendered or executed. Only the outer SVG wrapper is checked; this does not validate, sanitize, optimize or fetch SVG resources. Up to 200,000 characters.

How this is checked

2 reference checks passed These 2 cases were run when this page was built, on 3 December 2026, and all reproduce within the stated tolerance. The same cases are part of the automated tests that run on every change to Toolmoz. Engine version 1.

See the checks and where each expected answer comes from
  1. Case 1

    Inputs
    Source <svg></svg>
    Expected, and what Toolmoz gave
    text expected .icon { background-image: url("data:image/svg+xml,%3Csvg%3E%3C%2Fsvg%3E"); background-repeat: no-repeat; background-size: contain; } , Toolmoz .icon { background-image: url("data:image/svg+xml,%3Csvg%3E%3C%2Fsvg%3E"); background-repeat: no-repeat; background-size: contain; }
    Where the expected answer comes from
    Percent encoding writes each angle bracket as %3C/%3E and slash as %2F; all letters remain literal.
    Allowed difference
    exact
  2. Case 2

    Inputs
    Source <svg></svg>CSS class selector .mark
    Expected, and what Toolmoz gave
    text expected .mark { background-image: url("data:image/svg+xml,%3Csvg%3E%3C%2Fsvg%3E"); background-repeat: no-repeat; background-size: contain; } , Toolmoz .mark { background-image: url("data:image/svg+xml,%3Csvg%3E%3C%2Fsvg%3E"); background-repeat: no-repeat; background-size: contain; }
    Where the expected answer comes from
    The same encoded SVG with the class selector changed to .mark.
    Allowed difference
    exact

What this shows: the engine reproduces independently worked values for these cases. It does not prove every possible input is right. To test an answer you were given, see how to check a number; to see what is and is not checked across Toolmoz, see the accuracy ledger.

See a worked example

Worked example

A fixed demonstration, separate from the values you enter above.

Source
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#24533d"/></svg>
CSS class selector
.icon
Use SVG as
Background image

Example result

.icon {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%2210%22%20fill%3D%22%2324533d%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}