Loading SVG to Base64 converter...

How to Turn an SVG into a Base64 Data URI

Small icons, logos and loading spinners are often inlined so the page needs one request fewer. This page does the encoding part. For example, this 113-byte circle:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#0d9488"/></svg>

becomes this Base64, ready to sit behind data:image/svg+xml;base64,:

PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PGNpcmNsZSBjeD0iMTIiIGN5PSIxMiIgcj0iMTAiIGZpbGw9IiMwZDk0ODgiLz48L3N2Zz4=
Step 1

Paste or upload the SVG

Paste SVG markup into the editor or upload an .svg file. Sample loads a small gradient icon if you just want to see the result first.

Step 2

Read the result and any notes

The Base64 appears on the right a moment after you stop typing. If the SVG has an XML mistake, an outer element other than <svg>, or no xmlns attribute, an amber note says so, because a browser would draw nothing from that data URI.

Step 3

Copy it into a data URI

Copy or download the Base64, then put data:image/svg+xml;base64, in front of it and use the whole string as an img src or inside a CSS url().

Want the SVG smaller before you encode it? Run it through the SVG Minifier first. To check a Base64 string you already have, paste it into Base64 to SVG, and for PNG or JPEG files use Image to Base64. The MDN page on data URLs covers the format in detail.

Frequently Asked Questions

What exactly do I paste into my HTML or CSS?

The page gives you the bare Base64 string. Put data:image/svg+xml;base64, in front of it. In HTML that becomes <img src="data:image/svg+xml;base64,PHN2Zy..." alt="">, and in CSS background-image: url("data:image/svg+xml;base64,PHN2Zy...");. Keep the quotes in the CSS version, they make the url() easier to read and copy.

Why does my SVG show up blank as a data URI?

The most common cause is a missing xmlns="http://www.w3.org/2000/svg" on the <svg> tag. Inline SVG inside an HTML page works without it, but an <img> or a CSS background decodes the file as a standalone image and draws nothing. The second cause is an XML mistake such as an unclosed tag. This page checks for both and shows a note, while still encoding your text exactly as you wrote it.

Are accented letters and emoji in <text> encoded correctly?

Yes. The SVG is turned into UTF-8 bytes first and then into Base64, the same as the base64 command does. Plain btoa() in the browser either throws on characters like emoji or writes é as a single Latin-1 byte, which shows up as garbage once decoded. <text>José</text>, for example, becomes PHRleHQ+Sm9zw6k8L3RleHQ+.

Does an uploaded file get changed before encoding?

No. An uploaded .svg is encoded from its own bytes, so a byte-order mark, Windows line endings or a Latin-1 file with an encoding declaration end up in the Base64 exactly as they are on disk. If you edit the text afterwards, the page switches to encoding what is in the editor. Files over 10 MB, empty files and bitmap images renamed to .svg are turned away with a message instead.

Is Base64 always the best way to inline an SVG?

Not always. Base64 makes the SVG about a third bigger: the 504-byte Sample turns into 672 characters. Because SVG is already text, many people use a URL-encoded data URI in CSS instead, which is often shorter. Base64 is still handy when the value has to survive JSON, email templates or tools that mangle quotes and angle brackets. For anything larger than a small icon, a separate .svg file that the browser can cache is usually the better choice. Running the file through the SVG Minifier first also shrinks the Base64.

Is my SVG sent anywhere?

No. The encoding runs in your browser and the SVG is not uploaded to a server. Nothing is kept either: reload the page and the editor starts empty. Keep in mind that Base64 is an encoding, not encryption, so anyone with the string can turn it back into the SVG.