Skip to main content

SVG sizing and repair guide

Repair SVG viewBox, width, and height problems

An SVG can be valid XML and still render at the wrong size, appear clipped, or show an unexpectedly large empty area. The viewBox defines the internal coordinate system, while width and height describe the rendered viewport. This guide shows how to inspect and repair the relationship.

Start by opening a copy of the file with Analyze SVG. If the issue is malformed markup, use Repair SVG; if the coordinate system or explicit dimensions need a targeted change, use Fix SVG Size. Keep the original source because a sizing repair can change how the artwork is framed without changing its paths.

What viewBox controls

The viewBox has four numbers: min-x min-y width height. They define the coordinate rectangle that is mapped into the SVG viewport. The rendered width and height attributes or CSS size determine how large that rectangle appears on the page.

<svg viewBox="0 0 24 24" width="24" height="24">
  <path d="M3 12h18" />
</svg>

In this example, the artwork is authored in a 24-by-24 coordinate space and displayed at 24 CSS pixels in the markup. CSS can still scale the viewport, but the internal coordinates remain the same.

Common symptoms and likely causes

SymptomInspectPossible repair
Artwork is clippedThe path extends outside the viewBox rectangle.Expand or reposition the viewBox, or adjust the artwork bounds.
Large empty borderThe viewBox is much larger than the visible geometry.Measure the desired bounds and choose a tighter coordinate rectangle.
Icon looks stretchedViewport aspect ratio and viewBox aspect ratio differ.Check preserveAspectRatio and the intended display ratio.
Image has an unexpected intrinsic sizeWidth, height, CSS, and viewBox values disagree or are missing.Set explicit dimensions or use a deliberate responsive CSS rule.
Browser shows blank outputXML structure, namespace, references, or malformed path data.Run Repair SVG and inspect any external references or parser errors.

Before and after: framing the coordinate system

Loose frame

<svg viewBox="-40 -40 120 120">
  <circle cx="0" cy="0" r="12" />
</svg>

Tighter frame (illustrative)

<svg viewBox="-14 -14 28 28">
  <circle cx="0" cy="0" r="12" />
</svg>

The tighter frame reduces unused coordinate space around the circle. For real artwork, include stroke width, filters, shadows, and any off-canvas effects in the review rather than calculating bounds from the path alone.

Width and height are not the same as viewBox

Changing width and height changes the rendered viewport; changing the viewBox changes the coordinate window mapped into that viewport. If you change only width and height, the artwork can scale without being reframed. If you change only the viewBox, you can zoom or crop the artwork while the viewport stays the same. Use Fix SVG Size when you need to make explicit dimension changes, and inspect the output in both an <img> element and inline SVG if your application uses both.

Repair checklist

  1. Validate that the root element is <svg> and includes the SVG namespace where required.
  2. Record the current viewBox, width, height, and preserveAspectRatio values.
  3. Inspect whether visible paths, strokes, filters, masks, and shadows fall inside the intended frame.
  4. Make one sizing change at a time and compare the result in the target browser.
  5. Keep the original and test the repaired SVG in every destination that matters.