SVG troubleshooting

Check the SVG viewBox before resizing your icon

The SVG viewBox describes the rectangle of internal coordinates shown in the viewport. When an icon clips or has extra space, compare that rectangle with the artwork before changing only its CSS size.

Updated · Independent guide

Read the four viewBox numbers

The four values are min-x, min-y, width and height. They define a rectangle in the SVG’s coordinate system, while the displayed width and height describe its viewport. Those values often differ without either being wrong.

For example, a viewBox of 0 0 24 24 can hold an icon drawn in a 24-unit coordinate space while the displayed image is 48 pixels wide. This is an illustrative example, not a prescription to rewrite every icon to 24 units.

<svg xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 24 24" width="48" height="48">
  <circle cx="12" cy="12" r="8" fill="#2859db"/>
</svg>

Diagnose clipping, extra space and distortion separately

A larger CSS width cannot repair artwork lying outside the intended coordinate rectangle. Conversely, a roomy viewBox can make the visible artwork look small even when the image element itself is large.

Checks for SVG size problems
ProblemInspectTry on a copy
Clipped edgeArtwork, strokes and effects near the coordinate boundsAdjust the rectangle or artwork with its intended padding
Too much empty spaceWhether the viewBox extends beyond the needed boundsUse a deliberate crop rather than arbitrary scaling
Stretched shapeViewport proportions and preserveAspectRatioCompare the intended aspect ratio
Only one website clipsContainer styles and how the SVG is embeddedTest the same SVG in isolation and in the actual component

A repeatable SVG viewBox check

Keep the original before editing markup. SVG Viewer provides a viewing and editing route; a visual vector editor can help when the artwork itself also needs adjustment.

  1. Inspect the root SVG element for viewBox, width and height.
  2. Compare the visible artwork with the coordinate bounds, including strokes and effects.
  3. Change one variable at a time in a working copy and preview the result.
  4. Test at the intended small icon size and a larger size.
  5. Recheck in the actual button, page or receiving application.

Preserve the intended crop when exporting

Tight bounds are not automatically better. A logo may need breathing room or an alignment point, and a shadow may extend beyond its main paths. Write down which area the receiving component should show before trimming it.

For an SVG viewBox problem, inspect the internal rectangle and the external viewport as separate parts of the handoff. Use the vector guide for shape edits and the markup guide for a targeted coordinate change.

Questions, answered

Is viewBox the same as width and height?

No. viewBox defines internal coordinates; width and height describe the viewport where the SVG is displayed.

Must every icon use viewBox="0 0 24 24"?

No. Keep a coordinate rectangle appropriate to its artwork. The 24-unit example is only an illustration.

Will increasing CSS width fix clipped artwork?

Not necessarily. Inspect the coordinate bounds and the container’s rendering behavior as well.

Sources & checks

Product claims come from provider documentation. Steps and handoff checks are editorial guidance; we have not tested your file in these applications.

Privacy choices

Analytics helps us understand which guides people read. Advertising supports the site. You can choose each separately; the site works without either.

Read our privacy notice