Download Docs Demo npm

What does it do?

deSVG takes the <img /> tags you supply. It then grabs, using AJAX, the raw SVG you've set in the "src" attribute and replaces that <img /> with the <svg /> it downloads.

Include the JavaScript file on your page

<script src="path/to/desvg.js"></script>

Kick off deSVG

window.addEventListener('load', function(){
 	// 1. selector for the <img /> tags to replace
 	// 2. whether to strip inline style tags from SVG paths
	deSVG('.replace-svg', true);


Using this library will cause duplicate HTTP requests (one for initial image src download and then a subsequent one for AJAX-ing the SVG data), but development is full of trade-offs, so it's your call on the pros and cons of using this library. Sometimes it's a case of choosing between micro-optimisations vs. a sane development workflow. I trust your judgement.