Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including svg-to-dataurl with all npm packages installed. Try it out:

var svgToDataurl = require("svg-to-dataurl")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

svg-to-dataurl v1.0.0

😹 convert SVGs to DataURLs


😹 convert SVGs to DataURLs

Build Status Coverage Status NPM Version XO code style


$ yarn add svg-to-dataurl


Where svgStr is a string of SVG content, like this:

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="">
        <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />

You can convert the string to a DataURL with svgToDataURL():

const svgToDataURL = require('svg-to-dataurl')
const dataUrl = svgToDataURL(svgStr)

// data:image/svg+xml,

Visual Confirmation

You can test the string works by pasting the output into the address bar of your web browser:

Browser Example


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free