SVG to CSS Background
Paste SVG markup and get a complete background-image CSS rule — configure size, repeat, and position, then copy as a CSS class or inline style. Runs entirely in your browser.
Preview
Why use an SVG as a CSS background?
Embedding an SVG as a background-image data URI combines the scalability of SVG with the layout flexibility of CSS backgrounds. There is no separate HTTP request, no <img> tag needed, and you get full control over how the image fills, repeats, and positions itself within the element. It is commonly used for icon backgrounds, decorative elements, and patterns.
background-size: contain vs cover
contain scales the SVG as large as possible while fitting entirely inside the element — no cropping. Use this for icons and logos.
cover scales the SVG to fill the element completely — it may be cropped. Use this for full-bleed backgrounds.
auto renders the SVG at its intrinsic size as defined by the width and height attributes (or viewBox). If the SVG has no dimensions set, this may render at 0×0.
Frequently Asked Questions
How is this different from the SVG to Data URI tool?+
The SVG to Data URI tool outputs just the raw data: URL. This tool goes further — it wraps the URI in a complete CSS rule with background-size, background-repeat, and background-position properties you can configure visually, and shows a live preview of how the background actually renders.
Can I use any CSS selector?+
Yes — the Selector field accepts any valid CSS selector: a class (.icon), an ID (#logo), an element (button), or a pseudo-element (.icon::before). Type whatever matches your use case and the CSS class output updates instantly.
My SVG uses currentColor — will it work?+
currentColor is resolved against the element's computed color property. When used as a CSS background-image, the SVG is treated as an opaque image — currentColor is not inherited from the element and will fall back to black in most browsers. If you need dynamic color control, use the SVG Color Swapper to hard-code the colors first.
Is my SVG sent to a server?+
No. All encoding and output generation happens in your browser using JavaScript. Your SVG markup never leaves your device.
Related Tools
How to use
- Paste your SVG markup — the preview and CSS outputs update instantly.
- Edit the Selector to match your CSS target (e.g.
.icon,button::before). - Adjust Size, Repeat, and Position — the preview reflects each change live.
- Copy the CSS Class to paste into a stylesheet, or copy the Inline Style to paste into a
style=""attribute.