SVG to Base64
Convert SVG to Base64 online and use it as a generator, which provides ready-made examples for data URI, img src, CSS background-url, and others. The SVG to Base64 converter is identical to Image to Base64, with the only difference that it forces the mime type to be “image/svg+xml” (even if the uploaded file has a different content type or it cannot be detected). Please note that the SVG to Base64 encoder accepts any images types with a size of up to 50 MB. If you are looking for the reverse process, check Base64 to SVG.
About SVG
- Name: Scalable Vector Graphics
- Developer: W3C
- MIME types: image/svg+xml
- File Extensions: .svg, .svgz
- Uniform Type Identifier: public.svg-image
- Type of Format: Vector graphics
Output formats
If you do not know what output format you need, check the following examples to see how will look the result of the same Base64-encoded SVG image formatted in each of the available formats (as an example image I use a one-pixel red dot SVG file):
• Plain text:PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==
• Data URI:data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==
• CSS Background Image:.base64 {
background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==")
}
• HTML Favicon:<link rel="shortcut icon" href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==" />
• HTML Hyperlink:<a href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg=="></a>
• HTML Image:<img alt="" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==" />
• HTML Iframe:<iframe src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==">
The “iframe” tag is not supported by your browser.
</iframe>
• JavaScript Image:var img = new Image();
img.src = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==";
document.body.appendChild(img);
• JavaScript Popup:window.onclick = function () {
this.open("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==");
};
• JSON:{
"image": {
"mime": "image/svg+xml",
"data": "PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg=="
}
}
• XML:<?xml version="1.0" encoding="UTF-8"?>
<root>
<image mime="image/svg+xml">PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InJlZCIvPjwvc3ZnPg==</image>
</root>
If I missed an important output format for Base64-encoded SVG images, please let me know — I would love to implement it.
Comments (25)
I hope you enjoy this discussion. In any case, I ask you to join it.
I'd like to further develop it to identify all colors in the SVG-data and create inputfields with colors pickers, allowing you to change the SVG colors on the fly and see the difference on the fly.
So if there is some text: "fill:#f0f;" then it would drag out the #f0f color from the svg-data and allow you to change all occurances of that color.
This to quickly develop for example a hover-color for the svg.
Had I known this webpage existed before, I'd probably never have thought about doing all this. LoL
By the way, this encoder supports remote files as well as drag and drop feature.
But yeah it still has room for improvement. I still need to open InkScape and sometimes need to add color to the svg before i Drag drop it and get the CSS background-image. Hur really felt like I shouldnt have spent the time when this page already existens. :P
But yeah this would have been Good enough if I had found it before :)
Great job!
I completely agree that a drag and drop on whole page as well as autosubmit are a faster solution. Unfortunately, I'm not sure that I can implement it for this page (at least definitely not autosubmit).
Anyway, I'm very glad that you found this webpage useful, even if it has some limitations :)
Seems IE doesn't have the proper support for the FileReader API tho: https://caniuse.com/#feat=filereader
![](data:image/svg+xml;<data>)
For SVG, since it's text-based xml data, note also that URL encoding works for the
data:...
, likedata:image/svg+xml,%3Csvg%20width=…
. However the data becomes a bit more longer, in my (single) test it was 19 % longer data-string vs base64. May be good to know.Cheers
<iframe src="data:image/svg+xml;base64,PHN2ZyBjbGFzcz0ic3ZnIiB4bWxucz0iaHR0cDovL3d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tZT4NCiAgICA8L2JvZHk+DQogIDwvZm9yZWlnbk9iamVjdD4NCjwvc3ZnPg==">
The "iframe" tag is not supported by your browser.
</iframe>
inside html5 ..
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
i really need help on that. i tried all the possible conversion methods but i couldn't get the same result as your red circle example. any help would be appreciated. thanks
Thank you.