SVG to Base64
Encode SVG as Base64 or as a shorter percent-encoded Data URI — we show you which wins
Upload SVG
Drag & drop or click to upload
SVG files
Includes the MIME type prefix — paste straight into an HTML or CSS src
Upload a file to see the Base64 output…The string only, no prefix — for APIs and databases that add their own header
Upload a file to see the Base64 output…A finished CSS rule, ready to paste into a stylesheet
Upload a file to see the Base64 output…Copy this straight into your markup
Upload a file to see the Base64 output…Percent-encoding instead of Base64 — usually 20–30% shorter for SVG
Upload a file to see the Base64 output…Base64 Is Usually the Wrong Answer for SVG
You encode an icon, paste the string into your stylesheet, and it is enormous. Every tutorial says Base64, so you assume that is just the cost. It is not. Base64 adds a flat third to any file, and an SVG to Base64 conversion pays that tax for no reason.
SVG is already text. Percent-encoding it instead usually comes out 20 to 30% shorter. This page produces both and tells you the exact difference for your file.
We still give you the Base64 output, because some build tools and CMS fields demand it. Just know what it costs.
How to Encode SVG for CSS Without Wasting Bytes
- Minify with SVGO first. Design tools export a shocking amount of junk.
- Check for xmlns. Without it the Data URI renders blank.
- Drop the file in. Both encodings appear together.
- Read the comparison line. It names the winner in characters.
- Copy the shorter one. Usually the URI-encoded version.
Step one is where the real savings live. A logo exported from Figma often carries editor metadata, empty groups, and coordinates to twelve decimal places. SVGO regularly halves it.
SVG to Data URI: What Actually Gets Escaped
Percent-encoding only touches the characters that would break a URL. For SVG that is a short list:
| Character | Becomes | Why it matters |
|---|---|---|
% | %25 | The escape character itself — must go first |
# | %23 | Starts a fragment and cuts the URL in half |
< > | %3C %3E | Every tag in the file |
{ } | %7B %7D | Appears in embedded CSS |
" | ' | Swapped, not escaped — avoids closing the url() early |
The hash is the one that bites hardest. Any hex colour inside your markup contains one, so an unescaped file breaks the moment it has a fill="#333" in it.
A caveat on the quote swap: single quotes are valid XML, but if your SVG already contains single quotes inside attribute values, check the output before shipping.
What Breaks Inside an Inline SVG Background
Browsers treat an SVG loaded as an image as a sealed document. That protects you, and it also removes features you might be expecting.
- No scripts. Anything JavaScript-driven simply will not run.
- No external references. Web fonts, linked images, and outside stylesheets are blocked.
- No CSS inheritance.
currentColorcannot reach inside, so the icon will not follow your text colour.
That last point is the usual disappointment. If your icon has to change colour with a theme, a Data URI background is the wrong technique — use an inline SVG element or a CSS mask instead.
Building React components from your icons? The SVG to JSX converter turns the same file into a component whose colours you can control with props.
When to Reach for Base64 Anyway
Percent-encoding wins on size, but it is not always available. Three cases where Base64 is right:
- Strict CMS fields. Some editors mangle raw angle brackets and percent signs.
- Non-CSS contexts. APIs and JSON payloads usually expect the Base64 form.
- Very small files. Below a few hundred bytes the difference is not worth the thought.
For a raster image, this whole comparison is moot — percent-encoding binary data is far worse than Base64. Use the PNG to Base64 encoder or the general image encoder for those.
Decoding an SVG String
Going the other way? The Base64 image decoder recognises SVG from its payload, which starts with PHN2Zy or PD94bWw depending on whether the file opens with an XML declaration.
One warning we repeat often: never host an SVG from an untrusted source on your own domain. In an image tag it is harmless, but served directly it becomes a same-origin document that can run scripts.
Frequently Asked Questions
Why is percent-encoding shorter than Base64 for an SVG?
+
Do I really have to escape the # character?
+
Why does the output swap double quotes for single quotes?
+
My SVG shows up blank as a Data URI but fine as a file. What is missing?
+
Can I recolour the SVG with CSS once it is a background image?
+
Why will my SVG animation not run inside a background-image?
+
Is a Base64 SVG safe to use in an img tag?
+
Does gzip cancel out the Base64 penalty anyway?
+
My SVG contains a % sign and the URI output breaks. Why?
+
Should I run the file through SVGO before encoding?
+
The Short Version
Minify, then encode, then take the shorter output. For SVG to Base64 that usually means not using Base64 at all — the percent-encoded version does the same job with fewer characters.
And remember what an image-context SVG gives up: no scripts, no external assets, no colour inheritance. If you need those, inline the element instead.
Related Tools You Might Like
YAML Creator & Validator
Create, validate, and generate YAML files with predefined templates for deployment configurations
JWT Decoder
Decode and inspect JSON Web Tokens — view header, payload, and expiration
Markdown Editor
Write and preview Markdown with live rendering, toolbar, and export options
IP Lookup
Look up IP address geolocation, ISP, timezone, and network details
Caesar Cipher & ROT13 Decoder
Classical ciphers and encodings: Caesar, ROT13, XOR, Base64, hex, Morse
Hash Generator
Generate MD5, SHA-1, SHA-256, SHA-384, and SHA-512 hashes for text and files
