SVG stroke-linecap: Butt, Round, and Square Explained

The SVG stroke-linecap attribute determines the shape used at the end of open subpaths and dashed lines. By choosing between butt, round, and square, you control whether the stroke terminates precisely at its coordinates or extends past them with rounded or squared caps. Understanding how these three values modify stroke geometry is essential for precise vector alignment, path styling, and SVG animation.

How stroke-linecap Works

When an SVG renderer draws a path, the path’s coordinates define its mathematical center line. The stroke-width determines the thickness, expanding outward equally on both sides of that line. The stroke-linecap attribute dictates how the renderer finishes the stroke at the start and end coordinates of that line.

The Three stroke-linecap Values

1. butt (Default)

The butt value cuts the stroke off with a straight, flat edge directly perpendicular to the path direction at the exact endpoint coordinates.

2. round

The round value finishes the path with a semicircular cap extending past the endpoint.

3. square

The square value caps the line with a rectangular extension that extends past the endpoint.

Key Differences in Dimensions and Layout