SVG to CSS data URI
Encode an SVG for use in background-image.
FreeRuns in your browserNo signupUpdated 2026-10-29
Double quotes are swapped for single quotes so the result sits safely inside url("…").
Data URI size
218 B
SVG itself is 185 B
Overhead
18%
Encoding adds only the escaped characters
Preview
.icon {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f6bff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E");
}<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f6bff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E" alt="">
data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f6bff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E
About this tool
How it works and how to read the result.
Need this done for you?
Website design & development
Company websites designed and built to win trust and enquiries.
See the serviceWhat it does
This svg to data uri encoder turns SVG markup into a string you can put straight into CSS or an img tag, so a small icon needs no separate file or request. By default it uses minimal URL-encoding, which escapes only the characters that would break a CSS url() and keeps the rest readable. Base64 is available too. You get the full CSS rule, an img tag and the bare data URI, each with a copy button.
How to use it
- Paste the whole SVG element, from the opening svg tag to the closing one.
- Choose URL-encoded, which is smaller, or base64.
- Pick the CSS property you want, such as background-image or mask-image.
- Check the preview on the light and dark squares.
- Copy the CSS rule, the img tag or the URI on its own.
How to read the result
The sample check icon is 185 bytes of SVG. URL-encoded, the data URI is 218 bytes, an overhead of 18%. Most of that is the data:image/svg+xml, prefix and the escaped angle brackets, written as %3C and %3E. Double quotes inside the SVG became single quotes, so the whole value can sit safely inside url("...").
The same icon in base64 is 274 bytes, about 48% bigger than the SVG itself. Base64 always adds roughly a third plus the prefix, and the result cannot be read or edited by hand. Encoding every character with JavaScript's encodeURIComponent, which some guides suggest, gives 308 bytes here, larger still.
Use data URIs for small icons that appear in CSS: ticks in list bullets, arrows in select boxes, background patterns. Larger graphics are better as separate files, because the browser caches them once, while a data URI is downloaded again whenever the stylesheet changes.
For mask-image, the SVG's own colours do not matter; the shape is filled with the element's background colour.
Shrink the SVG first with the SVG optimiser for the smallest result. See website design and development for help with front-end performance.
Questions
Frequently asked.
Is base64 or URL-encoding better for SVG?
URL-encoding is usually smaller for SVG, because SVG is text and most characters can stay as they are. Base64 inflates every file by about a third. Base64 is only worth it if something in your build pipeline cannot cope with the escaped characters, which is rare today.
Why does my data URI not show up in CSS?
The usual causes are an unescaped # in a colour, which the browser reads as the start of a URL fragment, double quotes clashing with the quotes around url(), or a missing xmlns attribute. The encoder here fixes all three: it escapes #, swaps the quotes and adds xmlns if it is missing.
Your next move
Like what you see? Tell us about it.
A process that takes too long, a website that undersells you, or an idea ready to take shape. Tell us where you are and we will suggest a useful next step.
India · Working with clients worldwide