SVG Previewer
Shows SVG code as an image with zoom, backgrounds, and size details.
Add or fix the SVG viewBox so an icon scales to any size in CSS. The value comes from the width and height, or from the area the drawing really covers, with optional padding.
Only the <svg> start tag changes. The rest of the file stays as it is.
The viewBox has four numbers: min-x min-y width height. It says which area of the drawing's coordinate system to show. With it, the browser scales that area to whatever size the element gets.
viewBox="0 0 width height", when both are plain lengths (px, or units such as mm and in that convert to px).getBBox()), and the box around everything drawn becomes the viewBox.<svg> start tag is rewritten. Every other byte of the file stays as it was.<svg width="24" height="24"> with no viewBox gets viewBox="0 0 24 24".viewBox="10 20 100 50" with Drawn content, or "8 18 104 54" with 2 units of padding.<svg width="24" height="24"> becomes <svg viewBox="0 0 24 24">, and the icon fills whatever box CSS gives it.Without a viewBox, width and height only set the size of the window onto the drawing. Make the element bigger in CSS and you get a bigger window with the same small drawing in the corner, or a drawing cut off. With a viewBox the drawing scales with the element, which is what you want for icons and logos.
<foreignObject> are not measured.An attribute with four numbers, min-x, min-y, width, and height, that picks the area of the drawing to show. The browser scales that area to fit the element, which makes the SVG responsive.
For icons sized with CSS, yes, once a viewBox is present. Keep them when the SVG is used on its own or in an email, so it still gets a sensible default size.
The drawing reaches outside the width and height it was saved with. Choose Drawn content to fit the viewBox around the real shapes, and add a little padding.
No. Only the viewBox, width, and height attributes on the root element change. Paths and shapes are untouched.
Often used together with the SVG ViewBox Generator.
Shows SVG code as an image with zoom, backgrounds, and size details.
Shrinks SVG files with SVGO and shows the before and after side by side.
Checks SVG files for XML errors, broken references, typos, and unsafe code.