CSS Reference ยท Properties for Special Contexts
The stroke-width property
Reference for the CSS stroke-width property: set how thick SVG outlines and lines are, with numbers, lengths and percentages, plus examples and tips.
The stroke-width property sets the thickness of an SVG stroke. The stroke is centered on the geometry, so a width of 10 extends 5 units to each side of the edge.
A plain number is read in the SVG's user units, which means the stroke scales together with the drawing when the viewBox is resized.
CSS
circle { stroke: black; stroke-width: 8; }
Try it
Notice how the thicker strokes grow both inward and outward from the rectangle's edge.
Syntax
CSS
stroke-width: <length-percentage> | <number>;
- Initial value:
1 - Applies to: SVG shapes and text content elements
- Inherited: yes
- Animatable: yes (as a length or number)
- Computed value: an absolute length, or a percentage as specified
Values
| Value | Description |
|---|---|
<number> |
A width in user units, for example 4. The most common form. |
<length> |
A CSS length such as 2px or 0.1em. |
<percentage> |
A percentage of the diagonal-based size of the SVG viewport. |
Usage notes
- Zero hides it.
stroke-width: 0draws nothing, even ifstrokeis set. - It needs a stroke. The width has no visible effect while
strokeisnone, which is the default. - Negative values are invalid. The declaration is ignored.
- Scaling. When the SVG is displayed larger or smaller than its
viewBox, the stroke scales too. Addvector-effect: non-scaling-stroketo keep a constant on-screen width. - Overlap. Half the stroke lies outside the shape, so strokes on shapes near the
viewBoxedge can be clipped. Add padding in theviewBox. - Animating the width with a transition is cheap and works well for hover effects.
Browser support
Supported in every major browser.