Remove whitespace from SVG

Someone created a jsfiddle with a script that trims the svg for you which you can find here.

Here’s the script if you need to use it in your project:

var svg = document.getElementsByTagName("svg")[0];
var bbox = svg.getBBox();
var viewBox = [bbox.x, bbox.y, bbox.width, bbox.height].join(" ");
svg.setAttribute("viewBox", viewBox);
prompt("Copy to clipboard: Ctrl+C, Enter", svg.outerHTML);

Additionally, @user2415116 linked another website that achieves similar results:
svgcrop.com

Leave a Comment