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.
path { stroke: #1d4ed8; stroke-width: 4; }
Try it
Syntax
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-dasharrayandstroke-dashoffsetall refine how the stroke looks. - Lines need a stroke.
<line>and open<polyline>or<path>shapes withfill: noneonly show up ifstrokeis 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-strokekeeps the stroke width in screen pixels while the drawing scales. - Painting order. The stroke is drawn over the fill by default.
paint-ordercan reverse that. - HTML text. Browsers also offer the prefixed
-webkit-text-strokefor HTML text, which is a different property.
Browser support
Supported in every major browser for SVG content.