Base64 Encode/Decode

SVG to Base64 Converter: Encode SVG Images Online

Convert SVG images to Base64 data URIs for CSS backgrounds and HTML embedding. Preserves vector quality at any scale. Runs locally, no server upload.

100% client-side. Your data never leaves your browser.

🖼️

Drag & drop a SVG file here

or click to browse (max 50 MB)

Related Tools

Convert SVG to Base64

SVG (Scalable Vector Graphics) is the only web image format that remains perfectly sharp at any zoom level. This tool encodes SVG files to Base64 for embedding as data URIs in CSS, HTML, or JavaScript.

How to Use

  1. Drop an SVG file onto the upload area or click to browse
  2. The tool reads the file and encodes it to Base64
  3. Choose your output format: plain Base64, data URI, or CSS background
  4. Copy the result

SVG and Base64: When It Makes Sense

SVG is unique among image formats because it is already text (XML). This creates a choice that does not exist with binary formats like PNG or JPEG: you can embed SVG as Base64, as URL encoded text, or as inline markup.

Base64 data URI

background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0...);

The SVG bytes are encoded to Base64, wrapped in a data URI. The browser decodes and renders the SVG.

URL encoded data URI (often better)

background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' ...");

The SVG XML is percent encoded. This is typically smaller than Base64 for SVGs because SVG is already text and does not benefit from the binary to text step. The URL Encoder can help with the encoding.

Inline SVG

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <path d="M12 2L2 22h20L12 2z"/>
</svg>

Direct markup in HTML. Most flexible: you can style it with CSS, animate it, and manipulate it with JavaScript. No encoding needed.

When to Use Base64 for SVG

Despite URL encoding often being smaller, Base64 SVG data URIs are the right choice when:

Optimizing SVGs Before Encoding

Design tools export bloated SVGs. Before Base64 encoding, run the SVG through an optimizer:

SVGO

npx svgo input.svg -o optimized.svg

SVGO removes editor metadata, merges paths, rounds coordinates, and strips unnecessary attributes. Typical savings: 30-60%.

Manual optimization checklist

SVG Base64 in Icon Systems

Modern icon systems often inline SVGs directly in HTML for styling flexibility. But for CSS only icon solutions (pseudo elements, list markers), Base64 data URIs work well:

.alert::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  background-image: url(data:image/svg+xml;base64,PHN2Zy...);
  background-size: contain;
}

This approach keeps icons in CSS without touching HTML structure. Each icon is a separate data URI, typically 200-500 bytes of Base64 for simple path based icons.

File Size Comparison

SVG contentRaw SVGBase64URL encoded
Simple icon (1 path)200 B268 B~230 B
Logo (5-10 paths)1-3 KB1.3-4 KB1.1-3.4 KB
Complex illustration10-50 KB13-67 KB11-56 KB

For simple SVGs, the difference between Base64 and URL encoding is small. For complex SVGs, URL encoding wins consistently. Gzip compression narrows the gap further in HTTP delivery.

For raster image encoding, see PNG to Base64, JPG to Base64, or the general Image to Base64 converter.