Skip to content
Tutorials Center
My learning

Topics

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

Increasing stroke widths

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: 0 draws nothing, even if stroke is set.
  • It needs a stroke. The width has no visible effect while stroke is none, 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. Add vector-effect: non-scaling-stroke to keep a constant on-screen width.
  • Overlap. Half the stroke lies outside the shape, so strokes on shapes near the viewBox edge can be clipped. Add padding in the viewBox.
  • Animating the width with a transition is cheap and works well for hover effects.

Browser support

Supported in every major browser.