SVG to Base64 Converter

Convert .svg files or raw <svg> markup to Base64 and UTF-8 URL-encoded Data URIs locally—with live byte comparison and sandboxed preview.

100% Browser-Local · No Uploads · Free

Drop .svg files here, click to browse, or paste SVG code

Up to 20 SVG files (10 MB each) · Sandboxed <img> preview never executes SVG scripts

Drop more .svg files or paste SVG code
0 characters
File Size Comparison Waiting for SVG
UTF-8 vs Base64: —
Original SVG (UTF-8) 0 B
Base64 Data URI 0 B
UTF-8 URL-Encoded Data URI 0 B
Upload an .svg file or paste <svg> markup to compare exact sizes. 1 KB = 1,024 B
Zero sign-up · Runs locally in your browser

Real SVG Comparison: Base64 vs. UTF-8 Data URI (sample-icon.svg)

SVG to Base64 converter comparing Base64 Data URI and UTF-8 URL-encoded Data URI sizes for sample-icon.svg
SVG to Base64 side-by-side comparison measuring sample-icon.svg (64×64, 271 UTF-8 bytes) as Base64 Data URI (390 chars) vs. UTF-8 URL-encoded Data URI (310 chars — 20.5% smaller, saving 80 bytes).

Raw SVG Markup: sample-icon.svg (64×64, 271 UTF-8 bytes)

Includes required xmlns attribute for standalone Data URI rendering

<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" fill="none">
  <rect x="4" y="4" width="56" height="56" rx="14" fill="#2563eb"/>
  <path d="M22 39L32 22L42 39H22Z" fill="#ffffff"/>
  <circle cx="44" cy="22" r="5" fill="#14b8a6"/>
</svg>

Encoded Outputs Compared Side by Side (390 chars vs. 310 chars)

UTF-8 URI saves 80 bytes (20.5%) before Gzip/Brotli compression

/* Base64 Data URI (390 chars, +43.9% incl. prefix) */
data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI2NCIgaGVpZ2h0PSI2NCIgdmlld0JveD0iMCAwIDY0IDY0IiBmaWxsPSJub25lIj4KICA8cmVjdCB4PSI0IiB5PSI0IiB3aWR0aD0iNTYiIGhlaWdodD0iNTYiIHJ4PSIxNCIgZmlsbD0iIzI1NjNlYiIvPgogIDxwYXRoIGQ9Ik0yMiAzOUwzMiAyMkw0MiAzOUgyMloiIGZpbGw9IiNmZmZmZmYiLz4KICA8Y2lyY2xlIGN4PSI0NCIgY3k9IjIyIiByPSI1IiBmaWxsPSIjMTRiOGE2Ii8+Cjwvc3ZnPg==

/* UTF-8 URL-Encoded Data URI (310 chars — 20.5% smaller than Base64) */
data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64' fill='none'%3E %3Crect x='4' y='4' width='56' height='56' rx='14' fill='%232563eb'/%3E %3Cpath d='M22 39L32 22L42 39H22Z' fill='%23ffffff'/%3E %3Ccircle cx='44' cy='22' r='5' fill='%2314b8a6'/%3E %3C/svg%3E

How to Convert SVG Files or Raw Markup With SVG to Base64

Unlike bitmap formats such as PNG or JPG, SVG is already XML vector text—meaning you may have either a .svg file on disk or raw <svg> markup copied straight from Figma, Lucide, or Heroicons. This local SVG to Base64 converter handles both workflows inside your browser with zero server uploads:

  1. Choose your SVG to Base64 input mode: Drop up to 20 .svg files in Upload SVG File mode, or switch to Paste <svg> Markup to paste raw vector code directly (pressing Ctrl+V anywhere on the page also loads clipboard SVG markup).
  2. Compare SVG to Base64 vs. UTF-8 Data URI size: Encoding runs automatically. The live File Size Comparison bars measure your exact UTF-8 SVG byte length against both data:image/svg+xml;base64,... (SVG to Base64) and data:image/svg+xml,... (UTF-8 URL-encoded Data URI).
  3. Copy or download your output: Switch between Data URI (Base64), UTF-8 Data URI, Raw Base64 (with optional 76-character wrapping), HTML <img>, CSS, Markdown, or JSON, then copy or download as .txt.

SVG to Base64 in CSS vs <img> Tag

Developers use SVG to Base64 in two primary places—CSS declarations and HTML <img> elements—and understanding how both differ from inline <svg> DOM elements saves hours of debugging:

  • SVG to Base64 in CSS (background-image & mask-image): Pasting an SVG to Base64 Data URI into background-image: url("data:image/svg+xml;base64,...") is ideal for repeating patterns, custom select chevrons, checkboxes, and decorative dividers that belong in styling rather than semantic HTML. Because a CSS background-image cannot inherit text color (currentColor), either hardcode the desired fill/stroke in your SVG before running SVG to Base64, or apply the SVG to Base64 URI to CSS mask-image and paint it dynamically with background-color: currentColor.
  • SVG to Base64 in HTML <img> tags: Using <img src="data:image/svg+xml;base64,..." width="24" height="24" alt="..."> keeps your HTML document tree lightweight when the same icon repeats across dozens of table rows or cards, and browsers strictly isolate <img>-loaded SVGs so embedded scripts, external stylesheets, and accidental ID collisions (#grad1, #clip0) cannot leak into the parent page.
  • When inline <svg> is better than SVG to Base64: If you need to animate individual <path> elements with CSS, hover-recolor sub-shapes, or inherit currentColor without CSS masks, raw inline <svg> in HTML gives direct DOM access that an SVG to Base64 <img> or CSS background intentionally blocks.

SVG to Base64 vs. UTF-8 URL-Encoded Data URI

Because SVG source is readable text, you can embed it in CSS or HTML either as an SVG to Base64 Data URI (;base64,) or as a percent-encoded UTF-8 Data URI. Both remove an extra HTTP round-trip, yet they behave differently in production bundles:

Technical Factor SVG to Base64 (data:image/svg+xml;base64,) UTF-8 URL-Encoded Data URI (data:image/svg+xml,)
Uncompressed payload size ~33% larger than raw UTF-8 SVG text Usually close to raw SVG size (often 15%–25% smaller than SVG to Base64)
Gzip / Brotli compression Compresses less efficiently because XML patterns are obscured Compresses very well inside CSS and HTML responses
Escaping & parser safety Strictly ASCII alphanumeric (A-Z, a-z, 0-9, +, /, =); avoids quote or # conflicts Requires encoding # as %23 and careful single/double quote balancing
Readability in source code Opaque text; changing a color requires re-running SVG to Base64 Mostly readable; hex values (%232563eb) can be spotted in place
Pipeline & API compatibility Required by many JSON schemas, strict regex validators, and legacy email/PDF renderers Widely supported in modern browsers and CSS stylesheets

This SVG to Base64 tool calculates both representations simultaneously from your exact UTF-8 bytes so you can compare character counts before copying.

Pre-Encoding Checklist: xmlns, Minification, Unicode, and Safe Previews

Four practical engineering details make the difference between a broken icon and a rock-solid SVG to Base64 asset:

  1. Always include the XML namespace (xmlns): Inline <svg> inside HTML5 renders without xmlns="http://www.w3.org/2000/svg", but standalone SVG to Base64 Data URIs inside <img> or CSS url() render completely blank if xmlns is missing. In UTF-8 Data URI mode this tool checks for xmlns; in byte-exact SVG to Base64 mode your original bytes are preserved verbatim, so verify xmlns is present on your root <svg> tag.
  2. Minify vector markup before running SVG to Base64: Design exports from Illustrator or Figma often carry XML comments, editor namespaces, empty <g> groups, and 6-digit decimals. Trimming unneeded metadata before SVG to Base64 conversion reduces payload size before Base64's ~33% expansion applies.
  3. Unicode-safe UTF-8 encoding: Standard JavaScript btoa() throws an error on multi-byte characters (such as accented labels, CJK text, or symbols inside <text> elements). Our SVG to Base64 encoder converts markup through TextEncoder into exact UTF-8 bytes first so Unicode SVGs encode cleanly every time.
  4. Sandboxed preview security: Untrusted .svg files can hide <script> tags or onload handlers. Rather than injecting SVG code into the live DOM, this SVG to Base64 tool renders every preview strictly via a temporary local Blob URL inside an <img> element, where browsers disable script execution completely.

Working with raster graphics instead of vectors? Switch to PNG to Base64 for transparent bitmaps, JPG to Base64 for photographs, Image to Base64 for multi-format batch encoding, or decode any existing SVG to Base64 string back into a .svg file with Base64 to Image.

SVG to Base64 FAQ

Can I paste raw SVG code for SVG to Base64 without uploading a file?

Yes. Switch to the Paste <svg> Markup tab (or press Ctrl+V with SVG code on your clipboard) to run SVG to Base64 conversion immediately without saving a temporary .svg file first.

Does this SVG to Base64 encoder handle Unicode characters safely?

Yes. Because SVG is plain text, standard JavaScript btoa() crashes on multi-byte UTF-8 characters. This SVG to Base64 encoder converts your markup into exact UTF-8 bytes with TextEncoder before Base64 encoding, so Unicode text and symbols work cleanly.

Why does my SVG to Base64 image show up blank inside an img tag or CSS background?

The most common cause is a missing xmlns="http://www.w3.org/2000/svg" attribute on the root <svg> tag. Browsers require the XML namespace whenever an SVG to Base64 Data URI is loaded inside an img tag or CSS background.

Should I choose SVG to Base64 or UTF-8 URL-encoded Data URI for CSS?

For most modern CSS stylesheets, UTF-8 URL-encoded Data URIs are smaller and compress better with Gzip/Brotli. Choose SVG to Base64 when a JSON payload, strict parser, or legacy toolchain specifically expects Base64 alphanumeric encoding.

Can I style SVG to Base64 colors using CSS currentColor?

Not directly via fill or stroke selectors, because browsers isolate SVG to Base64 assets loaded in img tags or CSS background-image. To change icon colors with CSS, either update the fill attribute before encoding or use the SVG to Base64 URI with CSS mask-image and background-color: currentColor.

Does SVG to Base64 prevent duplicate SVG ID collisions on a page?

Yes. Unlike inline SVG injected into the DOM, loading an SVG to Base64 Data URI inside an img tag or CSS background-image keeps internal gradient and clipPath IDs isolated so identical IDs never clash across icons.

Could previewing a file in this SVG to Base64 tool run embedded JavaScript?

No. Untrusted SVG markup is never injected into the page DOM. Previews in this SVG to Base64 tool always load via a local Blob URL inside a standard HTML img tag, where browsers strictly block SVG scripts and external resource execution.

Is my SVG markup sent to a server during SVG to Base64 conversion?

No. SVG to Base64 encoding runs strictly inside your browser memory, and your .svg files or pasted vector code are never transmitted to any server or stored in browser storage.