Remove blank space in svg


Sun Mar 20 2022 17:13:46 GMT+0000 (UTC)

Saved by @max_demydenko #js #svg #svg-viewbox

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

This code shows prompt modal with selected svg code with modified viewbox property. After pasting this code instead of your svg there won't be any blank spaces in svg. Notes: SVG_INDEX - index of svg element on the page ('getElementsByTagName' can be replaced with other selector)