How Changing SVG Stroke-Width Affects Elements

The stroke-width property in SVG directly controls the thickness of the outline applied to a shape or path. Adjusting this value alters the visual weight of the element by expanding the stroke symmetrically outward and inward from the path’s center line. Changing the stroke-width impacts element boundaries, potential clipping within the SVG viewBox, interactions with scaling transformations, and the visual prominence of corner joins and line caps.

Center-Aligned Stroke Expansion

By default, SVG renders strokes centered directly on the coordinate path. When you increase the stroke-width, half of the added width expands outward, and the other half expands inward. For example, applying a stroke-width="10" to a <rect> places 5 pixels of the stroke outside the rectangle’s defined x, y, width, and height coordinates, and 5 pixels inside.

Visual Dimensions and ViewBox Clipping

Because strokes expand beyond the defined geometry of a shape, increasing stroke-width enlarges the overall visual footprint of the element without changing its underlying coordinate data. If a shape is positioned close to the edge of the SVG canvas, a large stroke-width can push the outer half of the stroke outside the defined viewBox, causing the edges of the stroke to be cut off unless the viewBox is expanded or overflow: visible is set.

Scaling and Resolution Independence

SVG elements scale vector graphics proportionally. When an entire SVG or a specific element is scaled via CSS or the transform attribute, the stroke width scales proportionally with it by default.

To keep the stroke thickness constant regardless of scaling, you can apply the vector-effect="non-scaling-stroke" attribute to the element. This ensures the stroke maintains its defined pixel width even when the shape shrinks or enlarges.

Interaction with Caps, Joins, and Dashes

Changing the stroke-width amplifies the effects of other stroke properties:

Units and Supported Values

The stroke-width property accepts: