CSS stroke-linecap Property

The CSS stroke-linecap property controls the shape of the endpoints of open SVG paths and line segments.

It determines whether a stroke ends with a flat edge, a rounded cap, or a square extension. The property also affects the appearance of dashes created with stroke-dasharray, making it useful for SVG icons, diagrams, charts, and decorative outlines.

stroke-linecap Syntax

The stroke-linecap property accepts one of three keywords: butt, round, or square.

Basic Syntax

svg path {
  stroke-linecap: round;
}

Available Values

svg path {
  stroke-linecap: butt;
}
svg path {
  stroke-linecap: round;
}
svg path {
  stroke-linecap: square;
}

CSS-Wide Keywords

svg path {
  stroke-linecap: initial;
}
svg path {
  stroke-linecap: inherit;
}
svg path {
  stroke-linecap: unset;
}
svg path {
  stroke-linecap: revert;
}
svg path {
  stroke-linecap: revert-layer;
}

The initial value is butt, which creates a flat endpoint that stops at the exact end of the path.

Property Values

Value Description
butt Creates a flat endpoint perpendicular to the path without extending beyond its endpoint. This is the initial value.
round Adds a semicircular cap that extends beyond the endpoint by half the stroke width.
square Adds a square-ended extension beyond the endpoint by half the stroke width.
initial Resets the property to butt.
inherit Uses the computed line cap value from the parent element.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value butt
Inherited Yes
Applies to Applicable SVG shapes, paths, and text elements
Computed value As specified
Animation type Discrete
Percentages Not applicable
Related properties stroke, stroke-width, stroke-linejoin, stroke-dasharray
Specification SVG 2

Valid Examples

svg line {
  stroke-linecap: butt;
}
svg path {
  stroke-linecap: round;
}
svg polyline {
  stroke-linecap: square;
}
svg g {
  stroke-linecap: round;
}

Invalid Examples

svg path {
  stroke-linecap: flat;
}
svg path {
  stroke-linecap: rounded;
}
svg path {
  stroke-linecap: 10px;
}
svg path {
  stroke-linecap: 50%;
}
svg path {
  stroke-linecap: round square;
}

The property accepts only one supported keyword. Lengths, percentages, multiple values, and unsupported keywords are invalid.

How It Works

An SVG stroke follows the geometry of a path. When the path has an open endpoint, stroke-linecap determines how the painted stroke ends.

Step 1: Create an SVG Line

<svg viewBox="0 0 240 80">
  <line x1="40" y1="40" x2="200" y2="40"/>
</svg>

Step 2: Define the Stroke

line {
  stroke: #2563eb;
  stroke-width: 12;
}

The line uses a blue stroke with a width of 12 user units. Its endpoints are flat by default.

Step 3: Change the Line Caps

line {
  stroke: #2563eb;
  stroke-width: 12;
  stroke-linecap: round;
}

The line now has rounded endpoints that extend beyond its original start and end coordinates.

Complete SVG Example

<svg viewBox="0 0 240 80" role="img" aria-label="Thick blue horizontal line with rounded endpoints">
  <line x1="40" y1="40" x2="200" y2="40" stroke="#2563eb" stroke-width="12" stroke-linecap="round"/>
</svg>

Important Consideration

The line cap changes the painted appearance of the endpoint without changing the path's underlying coordinates.

Comparing Line Cap Values

The three line cap values produce distinct endpoint shapes.

butt

.butt-line {
  stroke: #2563eb;
  stroke-width: 12;
  stroke-linecap: butt;
}

The stroke ends at the path endpoint with a straight edge. No additional length is painted beyond the endpoint.

round

.round-line {
  stroke: #0d9488;
  stroke-width: 12;
  stroke-linecap: round;
}

A semicircular cap extends beyond the endpoint by half the stroke width. This creates smooth, rounded ends.

square

.square-line {
  stroke: #a855f7;
  stroke-width: 12;
  stroke-linecap: square;
}

A rectangular extension adds half the stroke width beyond each endpoint while retaining a flat outer edge.

Visual Differences

Value Endpoint Shape Extends Beyond Path
butt Flat No
round Semicircular Yes, by half the stroke width
square Flat with a rectangular extension Yes, by half the stroke width

Choosing a Line Cap

Use butt for precise endpoints, round for softer outlines and icons, and square when a flat-ended stroke should extend beyond its path coordinates.

Line Caps and Stroke Width

The visible size of rounded and square line caps depends on the value of stroke-width.

Thin Stroke

.thin-round-line {
  stroke: #2563eb;
  stroke-width: 2;
  stroke-linecap: round;
}

The rounded extension is small because the stroke is thin.

Thick Stroke

.thick-round-line {
  stroke: #2563eb;
  stroke-width: 16;
  stroke-linecap: round;
}

The endpoint becomes more prominent as the stroke width increases.

Endpoint Extension

For round and square, the extension beyond each endpoint is half the stroke width.

Stroke Width Extension at Each Endpoint
4 2 user units
8 4 user units
12 6 user units
20 10 user units

Avoiding Clipped Caps

Rounded and square caps may extend outside an SVG viewport when a line endpoint is positioned too close to its boundary.

Leave sufficient space around thick strokes or adjust the SVG viewBox to accommodate the extensions.

Line Caps and Dashed Strokes

The stroke-linecap property also controls the ends of individual dashes created with stroke-dasharray.

Flat Dashes

.flat-dashes {
  stroke: #2563eb;
  stroke-width: 6;
  stroke-dasharray: 15 10;
  stroke-linecap: butt;
}

Each dash ends with a flat edge at its defined position.

Rounded Dashes

.rounded-dashes {
  stroke: #0d9488;
  stroke-width: 6;
  stroke-dasharray: 15 10;
  stroke-linecap: round;
}

Each dash receives rounded caps, extending its visible length beyond the nominal dash length.

Square Dashes

.square-dashes {
  stroke: #a855f7;
  stroke-width: 6;
  stroke-dasharray: 15 10;
  stroke-linecap: square;
}

Each dash receives square extensions at its endpoints.

How Caps Affect Gaps

Rounded and square caps extend into the gaps between dashes. If the gap is smaller than the stroke width, neighboring dash caps may touch or overlap.

Example of Overlapping Caps

.overlapping-dashes {
  stroke: #2563eb;
  stroke-width: 10;
  stroke-dasharray: 15 5;
  stroke-linecap: round;
}

Because each cap extends 5 units, the two caps bordering a 5-unit gap overlap. Increase the gap length to preserve visible separation.

Important Consideration

Dash lengths are measured along the path before line caps are added. The painted appearance may therefore differ from the numeric dash and gap lengths.

Creating Dotted Lines

Rounded line caps can transform very short dashes into circular dots.

Short Rounded Dashes

.dotted-line {
  fill: none;
  stroke: #2563eb;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 1 12;
}

Each short dash has rounded ends, producing a dot-like appearance.

Zero-Length Dashes

.round-dots {
  fill: none;
  stroke: #0d9488;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 0 14;
}

With round line caps, zero-length dashes produce circular dots.

Changing Dot Size

.small-dots {
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 0 12;
}
.large-dots {
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 0 20;
}

The stroke width determines the diameter of dots formed from zero-length dashes.

Changing Dot Spacing

.close-dots {
  stroke-dasharray: 0 10;
}
.wide-dots {
  stroke-dasharray: 0 20;
}

The second value controls the distance between successive dot centers.

Important Consideration

A zero-length dash with stroke-linecap: butt is not visible. Use round for circular dots or square for square dots.

Open and Closed Paths

Line caps are most noticeable at the endpoints of open paths.

Open Path

<path d="M20 60 H180" fill="none" stroke="#2563eb" stroke-width="12" stroke-linecap="round"/>

The path has two open endpoints, so both receive rounded caps.

Open Polyline

<polyline points="20,100 80,20 140,100" fill="none" stroke="#0d9488" stroke-width="10" stroke-linecap="square"/>

The first and last points receive square caps. The corner between the two segments is controlled by stroke-linejoin.

Closed Path

<path d="M20 20 H180 V100 H20 Z" fill="none" stroke="#a855f7" stroke-width="8" stroke-linecap="round"/>

The path is closed, so there are no open endpoints for line caps to affect.

Closed Shapes With Dashed Strokes

.dashed-circle {
  fill: none;
  stroke: #2563eb;
  stroke-width: 6;
  stroke-dasharray: 15 10;
  stroke-linecap: round;
}

Although a circle has no open path endpoints, each painted dash has endpoints that receive rounded caps.

Important Consideration

For continuous closed outlines, stroke-linecap has no visible effect. It becomes relevant when the outline contains dashes or other open stroke segments.

stroke-linecap vs. stroke-linejoin

The stroke-linecap and stroke-linejoin properties control different parts of SVG stroke geometry.

Property Controls Common Values
stroke-linecap The ends of open paths and individual dashes. butt, round, square
stroke-linejoin The corners where connected path segments meet. miter, round, bevel

Rounded Endpoints and Corners

.rounded-path {
  fill: none;
  stroke: #2563eb;
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
}

This creates rounded endpoints and rounded corners on an open SVG path.

Square Endpoints and Sharp Corners

.angular-path {
  fill: none;
  stroke: #a855f7;
  stroke-width: 10;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

This creates square-ended path endpoints and mitered corners.

Important Consideration

Use stroke-linecap for endpoints and stroke-linejoin for corners. Changing one does not automatically change the other.

Practical Examples

Rounded Icon Lines

.outline-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

Creates smooth outlines for SVG icons.

Flat-Ended Chart Line

.chart-line {
  fill: none;
  stroke: #2563eb;
  stroke-width: 4;
  stroke-linecap: butt;
}

Keeps the painted endpoints aligned with the path coordinates.

Square-Ended Divider

.svg-divider {
  stroke: #475569;
  stroke-width: 8;
  stroke-linecap: square;
}

Extends the painted divider slightly beyond its endpoints.

Rounded Dashed Line

.rounded-dashes {
  fill: none;
  stroke: #0d9488;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 15 10;
}

Creates a dashed line with rounded segment ends.

Dotted Outline

.dotted-outline {
  fill: none;
  stroke: #a855f7;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 0 14;
}

Creates circular dots along an SVG path.

Square Dots

.square-dots {
  fill: none;
  stroke: #ec4899;
  stroke-width: 6;
  stroke-linecap: square;
  stroke-dasharray: 0 14;
}

Creates square-shaped marks from zero-length dashes.

Inherited Line Caps

.icon-group {
  stroke: #2563eb;
  stroke-width: 4;
  stroke-linecap: round;
}

Child SVG paths inherit rounded line caps unless they override the property.

Reset Line Caps

.default-linecaps {
  stroke-linecap: initial;
}

Restores the initial butt value.

stroke-linecap Example

This example compares the three line cap values using identical SVG lines. Each line has the same length and stroke width, making the endpoint differences easy to see.

HTML Example

<div class="stroke-linecap-demo">
  <svg viewBox="0 0 600 240" role="img" aria-label="Three horizontal SVG lines showing butt, round, and square line caps">
    <line class="cap-butt" x1="90" y1="40" x2="510" y2="40"/>
    <line class="cap-round" x1="90" y1="120" x2="510" y2="120"/>
    <line class="cap-square" x1="90" y1="200" x2="510" y2="200"/>
  </svg>
</div>

CSS Example

.stroke-linecap-demo svg {
  display: block;
  width: 100%;
  height: auto;
}
.stroke-linecap-demo line {
  stroke-width: 20;
}
.stroke-linecap-demo .cap-butt {
  stroke: #2563eb;
  stroke-linecap: butt;
}
.stroke-linecap-demo .cap-round {
  stroke: #0d9488;
  stroke-linecap: round;
}
.stroke-linecap-demo .cap-square {
  stroke: #a855f7;
  stroke-linecap: square;
}
Browser Result

The blue line has flat endpoints, the teal line has rounded endpoints, and the purple line has square extensions. All three paths use the same start and end coordinates.

Comparing the Results

Line Value Appearance
Blue butt Flat endpoints without extensions
Teal round Rounded endpoints extending beyond the path
Purple square Square-ended extensions beyond the path

Changing the Stroke Width

.stroke-linecap-demo line {
  stroke-width: 30;
}

Increasing the stroke width makes the endpoint differences more noticeable.

Adding a Dash Pattern

.stroke-linecap-demo line {
  stroke-dasharray: 25 15;
}

Each line becomes dashed, and the selected cap style applies to the individual dashes.

Changing All Lines to Rounded Caps

.stroke-linecap-demo line {
  stroke-linecap: round;
}

This declaration would affect lines without a more specific line cap rule. To override the existing class rules, update or remove those declarations.

Accessibility Considerations

Line cap styles can affect the visibility and clarity of SVG icons, diagrams, and other graphics.

Maintain Visible Stroke Widths

Very thin strokes can be difficult to see, regardless of their endpoint style. Use appropriate stroke widths for the intended display size.

Avoid Ambiguous Endpoints

Rounded and square caps extend beyond the path coordinates. Consider this when precise alignment communicates important information.

Maintain Sufficient Contrast

Ensure that strokes remain distinguishable from adjacent colors and backgrounds.

Use Clear Dash Patterns

Rounded or square caps can reduce visible gaps between dashes. Choose sufficient spacing so individual segments remain recognizable.

Provide Accessible SVG Names

Informative SVG graphics should include accessible names or equivalent text descriptions.

<svg viewBox="0 0 200 60" role="img" aria-label="Blue horizontal line with rounded endpoints">
  <line x1="20" y1="30" x2="180" y2="30" stroke="blue" stroke-width="8" stroke-linecap="round"/>
</svg>

Avoid Style-Only Meaning

Do not rely solely on endpoint shape to communicate important information. Provide labels or other visual cues where necessary.

Test at Different Sizes

Verify that line caps remain clear when SVG graphics are resized, particularly in small icons.

Common Mistakes

Using Unsupported Keywords

svg path {
  stroke-linecap: rounded;
}

The correct keyword is round, not rounded.

Using Length Values

svg path {
  stroke-linecap: 10px;
}

The property does not accept lengths. Use stroke-width to control stroke thickness.

Confusing Line Caps With Line Joins

Line caps control endpoints. Line joins control corners where connected path segments meet.

Expecting Line Caps on Continuous Closed Paths

A closed path has no open endpoints. Line caps do not affect a continuous closed outline.

Forgetting to Define a Stroke

The initial stroke value is none. Line caps are not visible unless the element has a painted stroke.

Ignoring Endpoint Extensions

Rounded and square caps extend beyond the path endpoints. This can affect alignment and clipping.

Using Gaps That Are Too Small

Rounded or square caps can overlap when dash gaps are shorter than the stroke width.

Expecting Smooth Transitions Between Values

The property animates discretely. Transitions between butt, round, and square do not smoothly interpolate the cap shape.

Using Zero-Length Dashes With Butt Caps

Zero-length dashes with butt caps are not visible. Use round or square to create visible marks.

Important Considerations

Keep the following points in mind when using stroke-linecap:

  • It controls the shape of SVG stroke endpoints.
  • The initial value is butt.
  • The property is inherited.
  • It accepts butt, round, or square.
  • The butt value ends the stroke at the path endpoint.
  • The round value adds semicircular caps.
  • The square value adds rectangular extensions.
  • Rounded and square caps extend by half the stroke width.
  • The property does not change the underlying path coordinates.
  • It affects open path endpoints.
  • It also affects the ends of individual dashes.
  • It has no visible effect on continuous closed paths.
  • Round caps can create circular dots from zero-length dashes.
  • Square caps can create square marks from zero-length dashes.
  • Butt caps do not paint zero-length dashes.
  • Rounded and square caps can reduce visible gaps between dashes.
  • The stroke-width property controls the size of the caps.
  • The stroke-linejoin property controls corners, not endpoints.
  • The property animates discretely.
  • A painted stroke is required for line caps to be visible.
  • Thick caps may be clipped near SVG viewport boundaries.
  • Test endpoint appearance across supported browsers and display sizes.

Browser Support

The CSS stroke-linecap property is widely supported for SVG graphics in modern browsers, including Chrome, Edge, Firefox, and Safari.

All three values, butt, round, and square, have broad support for SVG strokes.

For current compatibility information, visit Can I Use? and search for stroke-linecap.

Feature Detection

@supports (stroke-linecap: round) {
  .rounded-outline {
    stroke-linecap: round;
  }
}

Feature queries can test whether a browser recognizes the property and value syntax.

Fallback Behavior

If a declaration is invalid or unsupported, the browser ignores it. The element uses another applicable value from the cascade or its inherited value, falling back to butt when no other value applies.

Testing Recommendations

Test thick strokes, dashed outlines, zero-length dashes, and SVG viewport clipping in the browsers you support.

Specifications

The stroke-linecap property is defined in the SVG 2 specification.

SVG 2 - stroke-linecap Property

The specification defines the endpoint geometry for the butt, round, and square values.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: stroke-linecap