Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Properties for Special Contexts

The stroke property

Reference for the CSS stroke property: set the paint of SVG outlines and lines with colors, gradients or currentColor, plus caps, joins and examples.

The stroke property sets the paint of the outline of an SVG shape, path, line or text. By default the stroke is none, so lines and outlines are invisible until you give them a paint. Without a stroke, an SVG <line> is not drawn at all.

The stroke is drawn along the edge of the geometry and is centered on it, so half of its thickness falls inside the shape and half outside. Its thickness comes from stroke-width.

CSS
path {
  stroke: #1d4ed8;
  stroke-width: 4;
}

Try it

Stroke colors, caps and joins

Syntax

CSS
stroke: none | <color> | <url> [none | <color>]? | context-fill | context-stroke;
  • Initial value: none
  • Applies to: SVG shapes and text content elements
  • Inherited: yes
  • Animatable: yes (colors interpolate)
  • Computed value: none, a computed color, or a URL reference with an optional fallback

Values

Value Description
none No outline is painted.
<color> Any CSS color.
url(#id) A gradient or pattern defined in the SVG, with an optional fallback color.
currentColor Uses the CSS color of the element.
context-fill, context-stroke Take paint from the context element; support varies, so check a compatibility table.

Usage notes

  • Related properties. stroke-width, stroke-linecap (butt, round, square), stroke-linejoin (miter, round, bevel), stroke-miterlimit, stroke-opacity, stroke-dasharray and stroke-dashoffset all refine how the stroke looks.
  • Lines need a stroke. <line> and open <polyline> or <path> shapes with fill: none only show up if stroke is set.
  • Crisp lines. A 1-unit stroke centered on an integer coordinate straddles two pixels and looks blurry. Shift by 0.5 units, or use shape-rendering: crispEdges.
  • Constant thickness. vector-effect: non-scaling-stroke keeps the stroke width in screen pixels while the drawing scales.
  • Painting order. The stroke is drawn over the fill by default. paint-order can reverse that.
  • HTML text. Browsers also offer the prefixed -webkit-text-stroke for HTML text, which is a different property.

Browser support

Supported in every major browser for SVG content.