Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS stroke Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The stroke property controls the paint used to draw the outline of vector shapes and glyphs — essentially the “pen” that traces a path. In SVG and other vector contexts it defines the visual paint (solid color, gradient, or pattern) applied to the path that forms the boundary of shapes such as , , and text glyphs. Unlike fills, which cover interior areas, the stroke paints along the path itself and therefore its visual result depends on the geometry of the path and how the stroke is combined with other painting steps.

The appearance produced by a stroke depends heavily on several companion properties that govern thickness, edges and dash patterns: for thickness you combine it with stroke-width; the shape of end caps is set by stroke-linecap; corner joins are controlled via stroke-linejoin; dashed outlines come from stroke-dasharray; and global transparency can be adjusted with stroke-opacity. In typical composition, stroke is often used together with fill so that an element can have a painted interior and a distinct outline; the visual balance between fill and stroke is a central aspect of vector styling.

Rendering details matter for how a stroke ultimately looks. By default a stroke is painted centered on the geometry of the path, so half the stroke’s visual thickness lies inside the shape and half outside — that interaction affects how adjacent strokes overlap and how joins appear at corners. The order in which stroke and fill are painted can change the final look; that order can be influenced by paint-order. For cases where transforms must not scale the stroke thickness, a vector-specific control such as vector-effect can be used to change how the stroke responds to transforms. These rendering behaviors make stroke a powerful tool for icons, diagrams, and typographic outlines, but also mean designers must consider how stroke metrics interact with path geometry and composition.

In practical use, designers combine stroke with line-cap and line-join settings to achieve crisp corners and smooth terminals, or with dash settings to create patterned or animatable outlines. Because stroke is fundamentally a paint applied to a path rather than a box-model border, techniques that work for CSS boxes (such as borders) are not a substitute for true vector strokes when precision on curves and joins is required.

Definition

Initial value
See individual properties
Applies to
SVG content
Inherited
Yes
Computed value
See individual properties
Animatable
See individual properties
JavaScript syntax
object.style.stroke

Syntax

stroke: <paint>

Values

  • <paint>The <paint> value defines how the stroke is painted and can be one of the following:
    • Color values - such as: red, #ff0000, rgb(255, 0, 0), hsl(0, 100%, 50%)
    • none - no stroke
    • currentColor - inherits the element’s text color

Example

<div class="example">
<h1>SVG stroke examples</h1>
<svg viewBox="0 0 200 120" class="icon" aria-hidden="true">
<circle class="outline" cx="40" cy="40" r="30" fill="none" />
<rect class="box" x="80" y="10" width="60" height="60" fill="none" />
<path class="zig" d="M10 90 Q 50 50 90 90 T 170 90" fill="none" />
<line class="dash" x1="10" y1="110" x2="190" y2="110" />
<text class="stroked" x="100" y="90" text-anchor="middle" dominant-baseline="middle">SVG</text>
</svg>
</div>
:root {
  --stroke: #2563eb;
  --accent: #f97316;
}

.example {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

.icon {
  width: 360px;
  height: 220px;
  overflow: visible;
}

/* circle uses a solid stroke and reduced opacity */
.icon .outline {
  stroke: var(--stroke);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-opacity: 0.9;
}

/* rect uses a different color and miter join */
.icon .box {
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linejoin: miter;
  stroke-miterlimit: 4;
}

/* path uses dashed stroke and round joins */
.icon .zig {
  stroke: #10b981;
  stroke-width: 5;
  stroke-dasharray: 12 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* long dashed line */
.icon .dash {
  stroke: #6b21a8;
  stroke-width: 4;
  stroke-dasharray: 6 6;
}

/* stroked text (SVG) - stroke provides outline */
.icon .stroked {
  fill: white;
  stroke: #111827;
  stroke-width: 2;
  font-size: 30px;
  font-weight: 700;
}

/* demo: using -webkit-text-stroke for HTML text fallback */
.example h1 {
  margin: 0;
  font-size: 16px;
  -webkit-text-stroke: 1px #111827;
  color: #111827;
}

Browser Support

The following information will show you the current browser support for the CSS stroke property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!