Skip to content
UniKit

SVG to Base64

Convert SVG markup to Base64 / data URLs and back: pick an .svg file (read as UTF-8 source) or paste the markup, the direction is auto-detected, the SVG is validated, URL-safe Base64 and prefix stripping are optional, and the real byte counts plus both data URI lengths are shown.

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 locally 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.

Result and real statistics

Lengths are the real character counts; the Base64 vs percent-encoding difference is computed, not guessed.

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

What this tool does

  • Inline an SVG icon into CSS or HTML: paste the markup and copy the ready-made data:image/svg+xml;base64,… string.
  • Go the other way: turn a Base64 string or Data URL from a design handoff or an API into readable SVG markup you can recolour.
  • Tick "Drop the data: prefix" when storing the value in JSON or a database so only the Base64 body is kept.
  • Tick "URL-safe Base64" when the string goes into a URL or an unquoted CSS context — the output uses only - and _ with no padding.

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

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cmVjdCB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIGZpbGw9IiMwZWE1ZTkiLz48L3N2Zz4=

Choosing an .svg file works too (it is read as UTF-8 source text, never decoded into pixels); when both are present the file wins. The stats row shows 134 SVG bytes, 180 Base64 characters, 179 URL-safe characters and a 206-character output, plus the length difference between the two data URI forms.

Frequently asked questions

How does it decide which direction to convert?

Input starting with data: is treated as a Data URL, input containing <svg, <?xml or <!-- as SVG markup, and everything else as Base64. You can also pin the direction to SVG → Base64 or Base64 → SVG manually.

When do I get "Not a valid SVG"?

When the decoded content has no <svg …> opening tag or no </svg> closing tag. The usual causes are a truncated Base64 payload, a copy that lost its tail, or pasting unrelated XML.

URL-safe Base64 vs regular Base64?

URL-safe output replaces + with - and / with _, and drops the trailing = padding, so the string survives URLs, unquoted CSS and file names. Both variants decode fine on the way back.

Is Base64 a compression?

No — it grows the payload by about 33% because every 3 bytes become 4 characters. It only makes binary/text safe to inline. Use SVG minification or gzip to actually shrink things.

Base64 or URL encoding (charset=utf-8) — which one?

Base64 is safe for every character at a constant +33% overhead. Full percent-encoding turns " and spaces and < > into three characters each, so it is usually longer (for this 24 × 24 icon: 206 characters as Base64 versus 257 percent-encoded — both numbers come straight from the result rows). To go shorter, either keep only the Base64 body (drop the data: prefix) or use the minimal escaping mode of the SVG to Data URI tool (181 characters for this icon). Both the preview and the stats run locally; nothing is uploaded.

Keywords:svg base64svg2base64data:image/svg+xml

Related tools