01What is SVG ViewBox Helper?
The viewBox attribute is four numbers that trip people up more than they should. SVG ViewBox Helper takes those four numbers from you, writes the attribute, and draws its shape so you can check it before pasting. A quick refresher on what the numbers mean, per the viewBox definition in the W3C SVG 2 spec. The first two, min-x and min-y, are the user-space coordinates of the top-left corner of the visible area. The last two, width and height, say how many user units are visible across and down. The browser then maps that rectangle onto whatever size the SVG is displayed at. By default it keeps the aspect ratio and centres the content, which is preserveAspectRatio="xMidYMid meet". The spec also says a negative or zero width or height disables the viewBox, and this tool follows that. You get four number fields labelled minX, minY, Width * and Height *. minX and minY start at 0. Width and height must both be greater than zero, or the tool shows a prompt instead of a result. Decimals and negative origins are fine. A value that can't be read as a number counts as 0. Once both sizes are valid, three panels appear. ViewBox String shows the attribute, for example viewBox="0 0 24 24", with a Copy button that copies just the value between the quotes. SVG Snippet gives a minimal <svg> element with your viewBox, the SVG namespace and a placeholder comment for your content. Visual Preview draws a dashed rectangle at the same aspect ratio, scaled so its longer side is 300 px. A red dot marks the top-left corner whenever the origin isn't 0 0. Here is a worked example. Enter minX -12, minY -12, Width 24 and Height 24 and you get viewBox="-12 -12 24 24". The point (0,0) now sits in the middle of the visible area, which makes drawing a centred circle as simple as cx="0" cy="0". Load the Wide Banner example and you get viewBox="0 0 1200 630". The preview box is 300 by 158 px, because 630 times 0.25 is 157.5, which rounds up. Everything is arithmetic on the numbers you type, so nothing is fetched or stored. The tool doesn't open an existing SVG or read its current viewBox. It doesn't show how preserveAspectRatio values change the fit, and the preview is a shape outline rather than your artwork.
Developers and icon designers setting up a new SVG who want the four viewBox numbers and the starter markup right before drawing anything. The tool runs entirely in your browser, so your data never leaves your device.
02How to use SVG ViewBox Helper
- Enter minX and minY. Both start at 0, which suits most icons
- Enter Width * and Height * for the area you want visible, in user units. Both must be above zero
- Or pick the Standard Icon or Wide Banner example to fill the fields for you
- Check the ViewBox String and the shape of the Visual Preview rectangle
- Click Copy for the bare value, or copy the SVG Snippet as a starting file
03Worked examples
- Input:
minX 0, minY 0, Width 24, Height 24 - Result:
viewBox="0 0 24 24" (preview rectangle 300 x 300 px) - Same values as the Standard Icon example.
- Input:
minX 0, minY 0, Width 1200, Height 630 - Result:
viewBox="0 0 1200 630" (preview rectangle 300 x 158 px) - The longer side scales to 300 px. 630 x 0.25 = 157.5, which Math.round takes to 158.
- Input:
minX -12, minY -12, Width 24, Height 24 - Result:
viewBox="-12 -12 24 24" (red origin dot shown) - The point 0,0 sits in the centre of the visible area.
- Input:
minX 0, minY 0, Width 16, Height 16 - Result:
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"> <!-- your content here --> </svg> - This is the SVG Snippet panel.
- Input:
Width 0, Height 100 - Result:
No result. Prompt: Enter width and height above to generate a viewBox string - Width and height must both be above zero. A non-numeric value counts as 0.
04Common use cases
- Starting a new icon on a 24 by 24 or 16 by 16 grid with a correct viewBox and namespace
- Setting up an SVG canvas that matches a 1200 by 630 Open Graph image
- Cropping an existing drawing by working out new min-x and min-y values so only part of it shows
- Centring the coordinate system with a negative origin like -12 -12 24 24 so shapes can be drawn around 0,0
- Checking the aspect ratio of a viewBox before placing it in a fixed-size container
- Showing a junior developer what each of the four viewBox numbers controls
05Tips
- Copy grabs only the four numbers, not viewBox="...". Paste it between the quotes of an existing attribute
- If an icon looks shifted or clipped, the drawing probably doesn't fit inside the min-x, min-y, width and height you set. Content outside that box is cut off unless overflow is visible
- A viewBox with no width or height on the <svg> lets the element scale to its container. Add width and height when you want a fixed default size
- Changing only width and height zooms. Changing only min-x and min-y pans. Keep that in mind when cropping by hand
06Related concepts
SVG viewBox, preserveAspectRatio, SVG coordinate system, Responsive SVG.
Frequently Asked Questions
What is SVG ViewBox Helper?
SVG ViewBox Helper is a free, browser-based developer tool on AIDToolStack. Calculate and visualize SVG viewBox values interactively. It requires no installation or sign-up and works entirely in your browser.
Is SVG ViewBox Helper free to use?
Yes. No sign-up, no fees and no usage cap.
Does SVG ViewBox Helper store my data?
No. It runs in your browser; nothing is uploaded.