Skip to content
UniKit

SVG to Base64 encoder

Encode SVG markup into raw Base64 or a data:image/svg+xml URL — pick an .svg file or paste the markup — with URL-safe output, line wrapping, the real Base64 length, inflation and both data URI lengths; paste Base64 back to recover the markup.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

The .svg file is read as UTF-8 text and encoded in your browser — nothing is uploaded.

Result preview

This tool outputs text, not a bitmap: the ready-to-paste data URL is in the text result below.

Encoded result and real statistics

Inflation = Base64 length ÷ SVG bytes − 1, computed from the real character counts.

Pick a file or paste something and the real encoded lengths show up here.

What this tool does

  • Inline an SVG icon into CSS: paste the markup, pick the Data URL mode and copy the background-image snippet.
  • Store the icon in JSON or a database column with the raw Base64 mode — no data: prefix, shorter and tidier.
  • Config files with a line-length limit (YAML, some nginx blocks) can wrap the output at 60 or 76 characters per line.
  • Received a Base64 blob and cannot tell what it draws? Switch to the decode mode to read the markup, recolour it and encode it again.

Example

Input

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><rect width="24" height="24" fill="#0ea5e9"/></svg>

Output

PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cmVjdCB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIGZpbGw9IiMwZWE1ZTkiLz48L3N2Zz4=

Raw Base64 is the default mode; choosing an .svg file (read as UTF-8 source) works too. The stats show 134 SVG bytes, 180 Base64 characters, 34.3% inflation and 1 encoded line, plus the real lengths of both data URI forms (206 characters Base64 / 257 percent-encoded); the text result ends with a ready-to-paste background-image: url("data:…").

Frequently asked questions

Why is Base64 bigger than the original file?

Base64 turns every 3 bytes into 4 characters, a 33.3% overhead before padding — this sample measures 34.3%. It exists to make data safe to inline, not to compress. Minify the SVG first if size matters.

Raw Base64 or Data URL?

Use the Data URL mode for CSS url() and HTML attributes because it carries the MIME type. Use raw Base64 for JSON, databases and plain data fields, and add the prefix yourself when needed.

Does URL-safe Base64 break decoding?

No. URL-safe output only swaps + for -, / for _ and drops the trailing = padding; the decoder restores both variants automatically.

Does line wrapping affect the result?

No. Newlines are whitespace inside Base64 and every decoder (including this one) strips whitespace before decoding. Wrapping only satisfies line-length limits in config files.

What if my pasted Base64 reports "invalid payload"?

Usually the string was truncated during copying, or it contains characters outside A–Z a–z 0–9 + / =. Check that it is complete and contains nothing else.

Keywords:svg2base64css background svg

Related tools