Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS: Trim SVG viewbox
/**
* Will trim the whitespace around the SVG's viewbox
*
*/
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.