SVG stroke is a presentation attribute that paints the outline of a shape or path. Use it on <line>, <circle>, <rect>, <polyline>, <path>, and related shapes.
Pair stroke with stroke-width. Then refine ends (stroke-linecap), corners (stroke-linejoin), and dashes (stroke-dasharray).
Baseline · Widely available.
Stroke presentation attributes are stable across modern browsers (widely available since about July 2020 for the CSS stroke property pairing).
Presentation attribute + CSS.
stroke and related stroke-* names also exist as CSS properties. If both are set, the CSS property wins.
Default stroke is none.
Shapes have no outline until you set a visible stroke. Default stroke-width is 1.
SVG elements you stroke (for example <line>, <path>, <circle>) also support the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.
Try it
Live Preview
Change thickness and line cap on a horizontal line.
12
Stroke is centered on the path. Caps only matter on open ends.
SVG
stroke-width="12" stroke-linecap="round"
Code
HTML Examples
Short, copy-ready snippets. Use Try It Yourself for a live editor.
stroke-dashoffset="15" slides the pattern along the path.
Useful for alignment and for draw-on style animations.
Pair with pathLength when you need predictable dash math.
Edge Cases & Pitfalls
Most missing-outline bugs are default paint, thin width, or clipping.
default
stroke defaults to none
No outline appears until you set a visible stroke. Remember default fill is black, which can hide the issue on filled shapes.
centered
Strokes are centered on the path
Half the width sits inside, half outside. Thick strokes near the viewBox edge can look clipped.
caps
linecap needs open ends
stroke-linecap affects open subpaths. Closed shapes mainly show stroke-linejoin at corners.
css
CSS overrides attributes
If both a presentation attribute and a CSS stroke-* property are set, the CSS value wins.
Compatibility
Browser Support
SVG stroke presentation attributes are supported in every modern browser.
✓ Baseline · Widely available
SVG stroke
Widely available across Chrome, Firefox, Safari, Edge, and Opera. Internet Explorer 9+ supports basic stroke, stroke-width, linecap, linejoin, and dasharray. CSS stroke property pairing is Baseline widely available since about July 2020.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+
Supported
strokeWidely supported
Bottom line: Safe for production icons, charts, and UI outlines. Prefer presentation attributes in these lessons so stroke stays visible in the SVG markup.
One line: outline paint + width, then caps, joins, or dashes as needed.
UA style
Default CSS Settings
Conceptual stroke defaults for SVG shapes:
defaults.css
/* Conceptual SVG stroke defaults */
.shape {
stroke: none;
stroke-width: 1;
stroke-linecap: butt;
stroke-linejoin: miter;
stroke-dasharray: none;
stroke-opacity: 1;
}
/* CSS overrides presentation attributes when both are set */
.outline {
stroke: #2563eb;
stroke-width: 4;
}
Prefer presentation attributes in these lessons so the outline stays visible in the SVG markup.
Frequently Asked Questions
stroke paints the outline of a shape or path. Pair it with stroke-width, and optionally linecap, linejoin, and dasharray.
It sets outline thickness. The stroke is centered on the path, so half the width sits inside and half outside.
It shapes the ends of open strokes. Values are butt (default), round, and square.
It shapes corners where segments meet. Values are miter (default), round, and bevel.
Set stroke-dasharray to lengths for dash and gap, such as "12 8". Use stroke-dashoffset to shift the pattern.
Default stroke is none. Set a visible stroke color and a positive stroke-width. Also check that fill="none" is not the only paint when you expected an outline.