SVG Data URIs Explained: Inlining Vectors the Efficient Way
What an SVG data URI is, why URL-encoding beats base64 for vectors, and how to inline SVG into CSS and HTML without an extra request, plus when NOT to inline.
Paste an SVG and get a ready-to-paste data: URI, URL-optimized for the smallest CSS payload or base64 for maximum compatibility, as a background-image, an inline <img>, or the bare URI. Live size comparison, one-click copy, 100% in your browser.
SVG to Data URI converts a pasted SVG into a ready data: URI, either URL-encoded for the smallest CSS payload or base64 for maximum compatibility. Copy it as a background-image, inline img src, or the bare URI, with a live size comparison. Free, one-click, and fully in your browser.
The GigAI SVG to Data URI converter inlines an SVG straight into your stylesheet or markup, so a small icon or background no longer costs a separate network request. It offers both encodings that matter in practice: a URL-optimized form that single-quotes attributes and percent-encodes only the characters that would break inside a CSS url("…") (the smallest, most CSS-friendly payload) and a classic base64 form for cases where a build step, email client, or tooling expects it. An optional cleanup pass strips editor cruft and collapses whitespace before encoding, which is usually the single biggest win on a data URI's size. Whatever you pick, the tool wraps the result in the snippet you actually paste: a CSS rule with background-image: url(…), an HTML <img src="…">, or the raw URI on its own. A live comparison shows the original SVG size, the encoded size, and how the two encodings stack up, so you can choose the smaller one with your eyes instead of guessing. Everything runs on your device with the browser's native SVG parser and encoder, so brand marks, unreleased icons and client artwork are never uploaded, stored or logged. It's the fast, private path from an SVG export to a zero-request inline asset.
Last updated
Paste SVG markup into the editor, drop a .svg file onto the workspace, or load a built-in example to see a data URI immediately.
Pick URL-encoded or base64, choose whether to output a CSS background, an <img> tag or the raw URI, and optionally turn on the cleanup pass. Everything regenerates live.
Check the size badges to confirm the encoding you chose is the smaller one, and glance at the preview to make sure the artwork still renders correctly.
Copy the finished snippet to your clipboard or download it, then drop it straight into your stylesheet or markup.
Pick the smallest, CSS-friendly URL-optimized encoding (single-quoted attributes with minimal percent-escaping) or classic base64 when a build step, tool or email client expects it. Swap between them and watch the size change.
Copy the exact thing you paste: a background-image: url(…) rule with your own selector, an <img src="…"> tag, or the bare data: URI on its own line. No manual wrapping.
See the original SVG size next to the encoded size, plus how URL-encoding and base64 stack up against each other, so you commit the smaller payload instead of guessing.
Collapse whitespace and strip editor metadata first, usually the biggest single win on a data URI, so what you inline is as small as it can be without changing how the artwork looks.
A checkerboard preview renders the SVG exactly as the encoded URI would, with light/dark backgrounds and zoom, so you confirm nothing broke in encoding before you copy.
Parsing and encoding run entirely on your device. Unreleased logos, client artwork and internal icons never leave the tab. Nothing is uploaded, stored or logged.
Inlining a small icon or background as a data URI removes a round-trip to the server, so first paint isn't blocked waiting on a tiny file, ideal for above-the-fold and critical CSS.
URL-encoding is almost always smaller than base64 for SVG, but not always. The side-by-side size comparison lets you choose with evidence instead of defaulting to base64 out of habit.
You get the finished snippet (background rule, <img> tag or raw URI) not just an encoded blob, so there's no fiddling with quotes, url() wrapping or charset once it's in your file.
Encoding happens locally in your browser, so confidential marks and unreleased assets never leave your machine. Close the tab and every trace is gone.
From quick one-off fixes to daily workflows, see how people put this tool to use.
Turn a small chevron or check into a URL-encoded background-image data URI so the component renders without a separate request: perfect for pseudo-elements and critical CSS.
Encode a mark as base64 to inline it directly in markup, avoiding an external asset URL in contexts where a hosted file is inconvenient or blocked.
Generate compact data URIs for a handful of core glyphs and store them as CSS custom properties, keeping the smallest icons request-free across the system.
Inline the few decorative SVGs a hero section needs so they never block first paint, using the size comparison to keep each payload as lean as possible.
Accepts SVG, and produces Data URI, CSS and HTML, all processed locally in your browser.
Minify and clean SVG files in your browser with SVGO, strip editor metadata, round coordinates, drop hidden layers and see the exact bytes and percentage saved. Nothing is uploaded.
Convert SVG to a clean React component in your browser, camelCased attributes, TypeScript or JS, memo, forwardRef and React Native output, with a live preview. Nothing is uploaded.
Open, paste or drop an SVG to view it on a checkerboard, light or dark canvas with zoom, live dimensions, a source-code pane and a full element/color report: 100% in your browser, nothing uploaded.
Aggressively minify SVG online: collapse whitespace, strip comments, metadata and editor namespaces, and squeeze markup to a single line with a live before/after size and % saved. 100% in your browser.
Shrink JPG, PNG and WebP images without a visible quality drop. Set the quality yourself, or compress to an exact target size like 100 KB. Free, entirely in your browser.
Decode a data:image/svg+xml URI back into raw SVG in your browser, handles base64 and URL-encoded payloads, with a live preview and one-click.svg download. Nothing is uploaded.
Go deeper on the concepts behind the svg to data uri.
Hit a snag? Here are quick fixes for the issues people run into most.
Wrap the URL-encoded URI in url("…") with double quotes, the encoding single-quotes the SVG's own attributes precisely so the outer double quotes stay intact. Also confirm the rule has a size (background-size or explicit width/height) so the image has room to render.
Base64 adds roughly a third to the byte count by design. For SVG, switch to the URL-encoded output and run the cleanup pass first: the size comparison will show the smaller of the two so you can pick it directly.
The input must contain a single well-formed <svg>…</svg> root. Strip any XML prolog, doctype or surrounding HTML and make sure every tag is closed. Running the markup through the SVG Validator first will point out the malformed part.
An <img> can't inherit CSS color, so a fill="currentColor" icon falls back to black. Hard-code the intended fill in the SVG before encoding, or use the CSS mask output instead of an <img> if you need it to follow text color.
URL-encoding is usually smaller than base64 for SVG. Start there and only switch to base64 if a tool or email client demands it.
Run the cleanup pass (or the SVG Optimizer first) before encoding. Removing editor metadata and whitespace shrinks the URI far more than the encoding choice does.
Keep data URIs for small assets, inlining a large, complex SVG bloats your CSS and can't be cached separately from the stylesheet.
For CSS, prefer the URL-encoded output: it stays human-diffable in your repo and avoids the ~33% size overhead base64 adds.
Set fill="currentColor" before encoding a monochrome icon so the inlined asset still inherits text color when used as an <img> or mask.
Recent updates and improvements to the svg to data uri.
Initial release, live SVG→data URI encoding with URL-optimized and base64 output, CSS / <img> / raw URI snippets, an optional cleanup pass, a live size comparison, and copy/download.
Added undo/redo history, keyboard shortcuts, curated examples, and a shareable-link option that reopens the tool with your SVG pre-loaded.
Clearer size badges comparing URL-encoded vs base64, and better errors when the input isn't a single well-formed <svg> root.
Every conversion runs entirely in your browser using its native SVG parser and encoder. Your markup is never uploaded to any server. Nothing is stored, logged or transmitted, so you can safely encode unreleased logos, client artwork or internal icons. Close the tab and every trace is gone.
Free, private and instant. SVG to Data URI runs right in your browser.