SVG viewBox Explained: Why Icon Sizes Don't Match

Contents
You've probably had this happen: you grab an SVG from an icon library, drop it into a button, and bump up the size — but the image stays the same, or only one corner zooms in and looks cropped. This isn't caused by bad CSS. It happens because the viewBox value and the width·height attributes in the SVG code do different jobs. Once you can read the four numbers in viewBox, you can spot the cause just by looking at the code.
Summary ① An SVG's size is determined separately by two things: the width·height you see on screen, and the viewBox that holds the shape coordinates. ② If there's no viewBox, the browser treats the width·height values as coordinate units, so scaling up doesn't make the image bigger — it just looks cropped. ③ Checking the four viewBox numbers (minX minY width height) tells you whether the problem is cropping, extra whitespace, or shifting.
The Problem: Why the Image Stays the Same When You Scale It Up
Say you download a 24×24 SVG file from an icon set and put it inside a button. You set style="width:64px;height:64px" to make it bigger, but the icon doesn't grow. Instead, only the top-left corner looks zoomed in, or the right and bottom edges are cut off entirely.
The opposite can happen too: you get unexplained whitespace around the image. Neither symptom goes away no matter how much you adjust the CSS. That's because the cause isn't in the CSS — it's inside the SVG code.
The Cause: width·height and viewBox Are Different Values
An SVG tag has size-related values in two places. One is the width·height attribute (or CSS), which sets the physical size the SVG takes up on screen. The other is the viewBox attribute, which sets the coordinate system that shapes like circle, rect, and path are drawn on.
When a viewBox is present, the browser automatically scales that coordinate system to fit the physical size — similar to how a photo gets automatically resized to fit a frame. That's why changing width·height makes the whole image scale up or down proportionally.
The trouble comes when there's no viewBox at all. Without it, the browser has no reference for resizing the shape coordinates, so it uses the width·height attribute values as the coordinate units themselves. If you then use CSS to increase only the physical size, just the canvas (the visible window) gets wider while the shapes inside stay at their original coordinates — so they end up clustered small in one corner or look cut off.
How to Check: Diagnose It From the Code Alone
You can tell what's wrong just by reading the code — no extra tools needed.
- Open the SVG code and find the
<svg ...>tag. - If there's no
viewBox="..."attribute at all, that's the cause. Take the existing width·height values and add them asviewBox="0 0 width height", and the problem is fixed. - If a viewBox exists but the third number (width) or fourth number (height) is smaller than the actual shape size, part of the image gets cropped.
- If the first two viewBox numbers (minX, minY) aren't 0, the shape appears shifted by that amount. You didn't move the shape — you moved the visible area (the window).
Check it with our tool. To see this relationship for yourself, paste in your SVG code and change the four viewBox numbers one at a time. The result updates instantly in the live preview, so you can compare directly which number causes cropping and which one causes shifting.
Free · No sign-up · Runs in your browser only (nothing is sent to a server)

Common Sticking Points
| Symptom | Cause |
|---|---|
| Scaling up doesn't make the image bigger; only one side shows | The viewBox attribute is missing entirely |
| Unwanted whitespace appears around the image | The viewBox ratio and the width·height ratio differ, so the image is scaled down and positioned inside |
| Part of the image looks cropped | The 3rd and 4th viewBox numbers (width·height) are smaller than the actual shape |
| The image looks oddly shifted | The 1st and 2nd viewBox numbers (minX·minY) aren't 0 |
Recap
Most SVG sizing problems come down to one of the four viewBox numbers. width·height only set the physical size on screen, while viewBox determines how the shape is laid out inside it.
If you mistake the two for the same thing, you'll waste time hunting for the cause in the CSS alone. Get in the habit of checking whether a viewBox exists and what its four numbers are first, and you can quickly narrow down most icon cropping and shifting problems.
Free · No sign-up · Runs in your browser only (nothing is sent to a server)
FAQ
What does each of the four viewBox numbers mean?
In order: minX, minY, width, height. The first two numbers are the point where the visible area starts in the coordinate system (the top-left origin), and the last two set how wide an area is shown starting from that point. The shape's own coordinates (like a circle's cx·cy) stay fixed regardless of these values — the viewBox only decides which part of that gets shown and at what scale.
Can I just delete the width·height attributes and keep only the viewBox?
Yes — in fact, many icon libraries do exactly this. Without width·height attributes, the SVG fills whatever size the parent element or CSS specifies, while the viewBox preserves the proportions between shapes. This is a common structure when you want icons to resize freely and responsively.
How do I fix an SVG that has no viewBox?
The simplest way is to take the existing width·height values and add them as viewBox="0 0 width height". For example, if it was width="24" height="24", add viewBox="0 0 24 24". After that, you can change width·height with CSS and the size will adjust while keeping the shape's proportions.
This article was adapted from our Korean original. Read the Korean original