Skip to main content

SVG to Data URI — URL-encoded & base64, CSS / HTML / bare

Inline any SVG as a data URI — URL-encoded (smaller) or base64 — with ready-to-paste CSS, HTML and bare-URI output, side-by-side size diff, 100% in-browser.

  • Runs locally
  • Category Developer & DevOps
  • Best for Formatting, validating, shrinking, or inspecting code-adjacent text.

Single .svg, up to 1 MB. Nothing leaves your tab.

Encoding
Output as
Output
Privacy. Both encoders run in your browser as plain JavaScript — no upload, no analytics. Open DevTools Network: request count stays at zero.

What this tool does

Turn SVG source into an inline data URI you can paste straight into CSS `background-image`, an HTML `<img src>`, or anywhere a URL is accepted — no extra HTTP request, no external file. Paste your markup or drop a `.svg` file and the tool produces both encodings at once: URL-encoded (the recommended one — it only escapes the handful of characters that break inside `url(...)`, so the result is smaller and stays human-readable) and classic base64. A live byte-for-byte size comparison shows you which encoding wins for your specific SVG; for most icons and logos URL-encoding is 20-40% smaller than base64 because it leaves the angle brackets, letters and digits untouched instead of inflating every 3 bytes into 4. Optional lightweight cleanup strips comments and collapses redundant whitespace before encoding, without touching paths or attributes. Copy any of three output flavours with one click: a full CSS rule, an `<img>` tag, or the raw data URI. Everything runs locally in your tab — the SVG never leaves the device, and the encoders are plain JavaScript you can audit in DevTools.

Tool details

Input
Files + Text
The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
Output
Live result + Copy + Preview
The result area focuses on usable output, with copy, download, or preview actions when supported.
Privacy
Browser-side processing
The main tool logic does not call an external API, so inputs normally stay in the current tab.
Save / share
Shareable URL state
Key settings are encoded in the URL so another person can reopen the same setup.
Performance budget
Initial JS <= 10 KB
No WASM budget is declared, keeping the tool quick to open on mobile.
Best fit
Developer & DevOps · Developer
Category and role tags drive related tools, internal links, and quick fit checks.

How to use

  1. 1. Input

    Paste or drop your content into the tool panel.

  2. 2. Process

    Click the button. All processing is local in your browser.

  3. 3. Copy / Download

    Copy the result or download to disk in one click.

How SVG to Data URI / CSS Background fits into your work

Use it in the small gaps between coding, reviewing, debugging, and shipping.

Developer jobs

  • Formatting, validating, shrinking, or inspecting code-adjacent text.
  • Preparing snippets for documentation, tickets, commits, or handoff.
  • Checking a small payload quickly without switching tools.

Developer checks

  • Run irreversible transforms like minify or obfuscate on a copy.
  • Keep secrets out of pasted snippets unless the tool explicitly stays local.
  • Use your normal tests or linter before shipping transformed code.

Good next steps

These links move the current task into a more complete workflow.

  1. 1 SVG Optimizer SVG optimizer — strip comments/metadata/empty attributes, round path decimals, collapse useless groups, minify in browser. No upload. Open
  2. 2 SVG to PNG Converter Rasterize SVG to PNG in your browser — custom size, 1×/2×/3× HiDPI scale, true transparent background, never uploaded. Open
  3. 3 Base64 Image Converter Image ⇄ Base64 — drag-drop PNG/JPG/WebP/SVG, get data URI for CSS / HTML / Markdown. Open

Real-world use cases

  • Inline a CSS background icon without an extra request

    You have a small chevron or search icon used in one component and you don't want a separate `.svg` file (and its HTTP round-trip) just for it. Paste the SVG here, leave URL-encoding selected, and copy the CSS output — `background-image: url("data:image/svg+xml,...")`. Drop it straight into your component's stylesheet. The icon ships inside the CSS, renders on first paint with no flash of missing image, and your network panel shows one fewer request. For a sprite of many icons this adds up fast.

  • Embed a logo in an HTML email

    Email clients block external images by default and many strip `<style>` blocks, so the reliable way to show a small vector logo is an inline data URI on an `<img>` tag. Paste the logo SVG, switch the output to the HTML `<img>` flavour, and copy. Note many older email clients (Outlook desktop) don't render SVG at all — for those, rasterize with svg-to-png-converter first and inline the PNG via base64-image-converter. Use this tool when your audience is on modern webmail (Gmail, Apple Mail) where SVG is supported.

  • Ship a Tailwind / CSS custom property full of vector art

    You want a reusable `--icon-check: url(...)` custom property so any element can pull in the same SVG via `background-image: var(--icon-check)`. Paste the icon, copy the bare data URI output, and assign it to the variable in your `:root` block. URL-encoding keeps the value short enough to stay readable in DevTools, which matters when you're scanning a `:root` with a dozen icon variables.

  • Compare URL-encoding vs base64 before committing

    You inherited a stylesheet where someone base64'd every inline SVG and the CSS file is heavier than it needs to be. Paste each SVG here, read the size diff — it shows base64 bytes vs URL-encoded bytes side by side. For the typical icon you'll see URL-encoding win by 20-40%. Swap the base64 blobs for the URL-encoded form, recompute your CSS bundle size, and you've trimmed real bytes off every page load with zero visual change.

  • Prototype a repeating SVG pattern as a background

    You designed a tileable dot or wave pattern in Figma and exported a small SVG tile. To preview it as a CSS background you need it inline. Paste the tile, copy the CSS rule, add `background-repeat: repeat`, and you can iterate on the look in the browser without a build step. When the pattern is finalized, css-pattern-generator can give you pure-CSS alternatives that skip the data URI entirely if you'd rather not inline.

Common pitfalls

  • Leaving `#` unescaped in a hand-written data URI. A `fill="#f00"` with a raw `#` truncates the SVG at the hash because the browser reads everything after `#` as a URL fragment. This tool escapes it to `%23` automatically — but if you copy a data URI from elsewhere and it renders blank, an unescaped `#` is the first thing to check.

  • Base64-encoding everything by reflex. Base64 adds a flat ~33% and makes the output unreadable. For SVG (which is already text) URL-encoding is almost always smaller and you can still eyeball it in DevTools. Only reach for base64 when a consumer specifically can't handle a URL-encoded payload.

  • Inlining a large illustration. Data URIs can't be cached separately from the file that holds them, so a 50 KB inlined SVG re-downloads with every page that references it. Keep inlining to small icons and logos; link big assets as external files.

  • Forgetting that `<img src="data:image/svg+xml,...">` needs the SVG to carry its own `xmlns`. Unlike inline `<svg>` in HTML, an SVG loaded via `<img>` or CSS `url()` is parsed as a standalone document and must declare `xmlns="http://www.w3.org/2000/svg"` or it won't render.

Privacy

The SVG you paste or drop is encoded entirely in your browser tab — the URL-encoder and the base64 encoder are plain JavaScript, no network call, no upload, no logging of what you converted. Open the DevTools Network panel and the request count stays at zero. One privacy caveat: this tool mirrors your SVG source into the shareable URL query string so a "share link" reproduces the same input. SVG markup is usually large, so the URL state is capped — oversize input simply isn't written to the URL. Still, if your SVG embeds anything you wouldn't put in a screenshot (a private API key in a comment, an unreleased brand mark), copy the output manually instead of sharing the URL.

FAQ

Tool combos

Folks in your role tend to reach for these alongside this tool.

Made by Toolora · 100% client-side · Updated 2026-06-14