On this page
An SVG can have a width of 24 pixels while its paths use coordinates hundreds of units wide. That is normal. The viewBox describes the internal drawing space; the rendered dimensions describe the viewport receiving it. Confusing these two spaces is a common reason icons look cropped, tiny, or unexpectedly stretched.
Separate drawing coordinates from display dimensions
The viewBox contains four numbers: minimum x, minimum y, width, and height. In viewBox="0 0 24 24", the visible coordinate window starts at the origin and spans 24 units in both directions. It does not require the SVG to render at 24 CSS pixels.
Use the SVG path scaler when you actually need to change path coordinates, such as moving a 48-unit icon into a 24-unit family. Do not scale geometry merely to make a standalone SVG display larger; changing its CSS dimensions is usually enough.
The distinction matters when handing files between tools. A drawing can be centered in a large artboard yet occupy only a small portion of it. Its SVG may be valid while appearing undersized next to other icons. Inspect both the viewBox and the visible bounds before changing either one.
Understand how the viewport receives the drawing
The viewport is the rectangular area allocated to the SVG. Its proportions may differ from those of the viewBox. By default, preserveAspectRatio uses centered alignment and a meet behavior, fitting the entire viewBox within the viewport without distortion.
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" width="48" height="32"
preserveAspectRatio="xMidYMid meet">
<circle cx="12" cy="12" r="8" fill="currentColor" />
</svg>This circle stays circular. The square drawing space fits inside the wider viewport, leaving unused horizontal space. With preserveAspectRatio="none", the same drawing stretches independently in each direction and the circle becomes an ellipse.
The MDN viewBox reference explains the coordinate window. The preserveAspectRatio reference explains the alignment and scaling choices. For ordinary interface icons, preserving proportions is generally the intended behavior; distortion should be an explicit exception rather than a quick fix for whitespace.
Fix cropping by checking painted bounds
A path's coordinates are not its complete painted bounds. Strokes extend on both sides of a centerline. A two-unit stroke along x=0 reaches one unit into negative coordinates, outside a viewBox that begins at zero.
Check the artwork at every edge. For a simple 24-unit square with a two-unit outline, placing its outline centerline at one and twenty-three keeps its outside edges within the canvas. Round caps and sharp miter joins can extend differently, so do not evaluate complex artwork using path endpoints alone.
Filters add another complication: a shadow can be clipped by its filter region even when the root viewBox has enough space. Diagnose the clipping boundary before enlarging the canvas. Otherwise you may add whitespace without restoring the missing effect.
Use a temporary contrasting background and a visible viewport border during inspection. Compare a stroked version with a filled silhouette. If clipping disappears when the stroke is removed, the problem is likely painted bounds rather than the path's basic placement. Fix the geometry or drawing window, then remove the debugging styles.
Normalize a family without losing alignment
Suppose a source icon uses a 48-by-48 coordinate window and a four-unit stroke. To convert it to a 24-unit system, scale coordinates by one half and reduce the stroke to two units. If you scale only the coordinates, the relative visual weight changes.
A uniform transform can scale the artwork without rewriting every path command. However, transformed strokes, nested groups, and later editing expectations need review. A normalized source file should be understandable to the next person maintaining the icon, not merely render correctly once.
If the source viewBox begins at a nonzero coordinate, account for translation as well as scale. Mapping a window that begins at 100,100 into a zero-origin canvas requires moving the drawing before or during scaling. Multiplying coordinates alone preserves the unwanted offset.
Check exported dimensions with the image resizer calculator when raster previews are part of delivery. Raster dimensions and vector coordinates solve different problems, but documenting both prevents accidental size assumptions. Keep a fixture showing each normalized icon in the same CSS-sized box.
Debug with a repeatable sequence
Use a diagnostic sequence rather than editing attributes until the picture looks right. First inspect the root width, height, and viewBox. Then inspect CSS that might override the displayed size. Finally inspect transforms, strokes, clip paths, masks, and filters inside the drawing.
A useful sequence is:
- Render the SVG alone on a neutral page with an explicit square size.
- Add a viewport border to distinguish layout space from artwork.
- Confirm that the viewBox encloses all intended painted geometry.
- Remove accidental transforms or inherited sizing rules one at a time.
- Compare the corrected icon with a known-good family member.
Consult the SVG coordinate systems specification when nested viewports or transformations complicate the result. For related drawing practices, see the icons and illustration guides.
Write down the actual cause after fixing a difficult asset. A short note such as “source artboard included 20 units of empty space” is more useful than “SVG sizing was broken.” That creates a reusable diagnosis and helps future contributors distinguish geometry errors from layout errors before they introduce compensating CSS.
Calculate one mapping before editing paths
Use this calculation as a quick export sanity check.
Consider a source window of 100,100,48,48 rendered into a 24-by-24 viewport. The uniform scale is one half. A source point at 112,124 sits 12 units right and 24 units below the window's origin, so it maps to 6,12 in the normalized space. Subtract the source origin first, then multiply by the scale. This simple calculation catches translation mistakes before you rewrite an entire drawing.
Now put that normalized square into a 48-by-32 viewport with centered meet behavior. Its scale becomes 32 divided by 24, and the drawing occupies a 32-by-32 region with eight pixels of unused space on either horizontal side. That whitespace is expected, not evidence of incorrect coordinates. If you require a wider symbol, change the artwork intentionally rather than stretching the circle or removing aspect-ratio preservation to fill the box.
Key takeaways
- The viewBox describes drawing coordinates, not mandatory rendered pixels.
- Preserve aspect ratio unless stretching is an intentional design decision.
- Include stroke and effect extents when checking for clipping.
- Normalize translations, geometry, and stroke weight together.
- Debug the viewport, coordinate window, and internal artwork separately.
Reach designers & developers at work
Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.
Become a sponsor