Loading...
Loading...
We use cookies to enhance your experience, analyze site usage, and serve personalized content. By clicking "Accept All," you consent to our use of cookies. See our Cookie Policy and Privacy Policy for details.
Convert SVG code to CSS background-image with optimized data URI
.svg-icon {
width: 24;
height: 24;
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%2210%22%2F%3E%3Cpath%20d%3D%22M12%206v6l4%202%22%2F%3E%3C%2Fsvg%3E");
background-size: contain;
background-repeat: no-repeat;
}Converts SVG markup to CSS values for background-image, mask-image, inline SVG (content property), and clip-path modes. Supports URL-encoded and base64 encoding, applies optimization before conversion, shows a live preview of the rendered result, and compares byte sizes of the original SVG, URL-encoded, and base64 versions.
Embedding SVGs in CSS requires proper encoding and wrapping for each CSS property. This tool automates the conversion so developers can use SVGs in stylesheets without manual string manipulation.
Frontend developers, CSS authors, and UI engineers who embed vector graphics as CSS background images, masks, or clip-paths.
Paste SVG markup into the input area — it will automatically be optimized in the preview pane.
Select the output mode: background-image, mask-image, inline (content), or clip-path.
Choose encoding: URL-encoded (smaller, human-readable) or base64 (binary-safe, larger).
Review the live preview showing the CSS-rendered SVG on a sample element.
Check the size comparison table showing original bytes vs. URL-encoded bytes vs. base64 bytes.
Click Copy CSS to copy the generated CSS declaration(s) to your clipboard.
Input: <svg viewBox="0 0 24 24"><path d="M12 2L2 22h20z"/></svg> with background-image mode and URL encoding → output: background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2L2 22h20z'/%3E%3C/svg%3E");Input: same SVG with mask-image mode and base64 encoding → output: mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEyIDJMMiAyMmgyMHoiLz48L3N2Zz4=");this tool is for individual SVGs; use an SVG sprite generator for multiple icons.
fill, stroke, and colors are ignored.
CSS background-images and masks do not render SVG animations.
Compress images with quality control for JPEG, PNG, and WebP formats
Resize, compress and convert images with batch processing support
Extract and view EXIF metadata from images
Create favicons from images or text for all platforms and devices
Dive deeper with our comprehensive guides and tutorials.