Member-only story
6 common SVG fails (and how to fix them)
Someone recently asked me how I approach debugging inline SVGs. Because it is part of the DOM, we can inspect any inline SVG in any browser DevTools. And because of that, we have the ability to scope things out and uncover any potential issues or opportunities to optimize the SVG.
But sometimes, we can’t even see our SVGs at all. In those cases, there are six specific things that I look for when I’m debugging.

1. The viewBox
values
The viewBox
is a common point of confusion when working with SVG. It’s technically fine to use inline SVG without it, but we would lose one of its most significant benefits: scaling with the container. At the same time, it can work against us when improperly configured, resulting in unwanted clipping.
The elements are there when they’re clipped — they’re just in a part of the coordinate system that we don’t see. If we were to open the file in some graphics editing program, it might look like this:

The easiest way to fix this? Add overflow="visible"
to the SVG, whether it’s in our stylesheet, inline on the style
attribute or directly as an SVG presentation attribute. But if we also apply a background-color
to the SVG or if we have other elements around it, things might look a little bit off. In this case, the best option will be to edit the viewBox
to show that part of the coordinate system that was hidden:

overflow="hidden"
and editing the viewBox.There are a few additional things about the viewBox
that are worth covering while we’re on the topic:
How does the viewBox
work?
SVG is an infinite canvas, but we can control what we see and how we see it through the viewport and the viewBox
.
The viewport is a window frame on the infinite canvas. Its dimensions are defined by width
and height
attributes, or in CSS with the corresponding width
and height
properties. We can specify any length unit we want, but…