A virtual teacher who reveals to you the great secrets of Base64

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.


How to convert SVG to Base64 online

  1. Choose the source of image from the “Datatype” field.
  2. Paste the URL or select a SVG image from your computer.
  3. If necessary, select the desired output format.
  4. Press the “Encode SVG to Base64” button.
  5. Download or copy the result from the “Base64” field.

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 (8)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • SeoSeongwon,
    Thank you for your kindness.
  • Mauro,
    Excelentisimo! The best tool to convert remote svg to data:image!!
  • Elrinth,
    Doh, so I implemented this for myself aswell. Mainly to be able to quickly drag svg images into a webpage and get the CSS for background-image. Soooo the difference from here is that I simply drag n drop the files on the whole page rather than clicking Local file*. I also support remote url, but it requires CORS chrome plugin allowance. :P

    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
    • Administrator,
      Hey! Thank you for your comment.
      By the way, this encoder supports remote files as well as drag and drop feature.
      • Elrinth,
        Yeah I noticed. But drop area ain't whole page and ain't direct upload. Mine simply drag drop and it directly works. Much faster workflow. Verifies it's mimetype and give a Nice message if it isnt right mine type etc etc.

        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!
        • Administrator,
          Thank you for details and kind words!

          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 :)
          • Elrinth,
            At first I did some ASP.NET file uploader, because I am using Windows and IIS Express is builtin and fast get working in VSCode as webserver. HOWEVER, the fine thing is that with the FileReader API, you never need to upload the actual SVG file to the server! So you can just drag a image to the browser and see the image and get information about it all in javascript before it's even uploaded! So it's all just a plain html file now! :) I'm gonna put it on githabb and I'll share it with you so you can see it.

            Seems IE doesn't have the proper support for the FileReader API tho: https://caniuse.com/#feat=filereader
  • Tom,
    Your work is appreciated!
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.

Loading...