SVG Stroke

What You’ll Learn
In SVG, stroke styles the outline of shapes and paths. Stroke properties control colour, thickness, line ends, corners, and dash patterns.
This page explains the most useful stroke properties and shows practical examples you can copy into your SVGs.
⚡ Quick Reference — Stroke Properties
Colour
strokeOutline colour
Width
stroke-widthOutline thickness
Ends
stroke-linecapbutt / round / square
Corners
stroke-linejoinmiter / round / bevel
Dashes
stroke-dasharrayDash/gap pattern
Dash offset
stroke-dashoffsetShift the dash pattern
Basic Syntax
<element
stroke="#0f172a"
stroke-width="4"
stroke-linecap="round"
stroke-linejoin="round"
stroke-dasharray="8 6"
/>👀 Live Preview — Caps, Joins & Dashes
These quick previews show how stroke settings change the look of outlines.
Line caps
Line joins
Dash pattern
1
Stroke on Multiple Shapes
A rectangle, circle, and line each use different stroke settings.
index.html
<svg width="240" height="200" viewBox="0 0 240 200">
<rect x="20" y="26" width="90" height="70" fill="none" stroke="red" stroke-width="5" />
<circle cx="170" cy="62" r="34" fill="none" stroke="blue" stroke-width="4" stroke-linecap="round" />
<line x1="20" y1="150" x2="220" y2="150"
stroke="#10b981" stroke-width="8" stroke-linecap="round" stroke-dasharray="14 10" />
</svg>2
Dash Offset (Animated Look Without Animation)
stroke-dashoffset shifts the dash pattern along the path. It’s the key property used in many stroke animations.
index.html
<svg width="240" height="120" viewBox="0 0 240 120">
<line x1="20" y1="40" x2="220" y2="40"
stroke="#f97316" stroke-width="10" stroke-linecap="round"
stroke-dasharray="18 12" stroke-dashoffset="0" />
<line x1="20" y1="80" x2="220" y2="80"
stroke="#f97316" stroke-width="10" stroke-linecap="round"
stroke-dasharray="18 12" stroke-dashoffset="14" />
</svg>💡 Best Practices
Do
- Use
stroke-linecap="round"for friendly UI strokes - Use consistent
stroke-widthacross related icons - Set
fill="none" - Use
stroke-dasharrayfor dashed and dotted lines - Use
stroke-dashoffsetfor animated dash effects
Don’t
- Forget
strokeon lines and polylines (they won’t show) - Use huge stroke widths without expanding the viewBox/canvas
- Mix stroke caps/joins randomly across one icon set
- Overuse heavy dash patterns in dense charts
- Hide focus/hover styling on interactive stroked elements
❓ Frequently Asked Questions
stroke draws the outline of a shape. You control its colour, width, dash pattern, and corner/endpoint styles.It sets the thickness of the outline. Larger values produce thicker strokes.
It controls line ends:
butt (flat), round (rounded), or square (extends past the end).It controls corners where segments meet:
miter, round, or bevel.Use
stroke-dasharray for dash/gap lengths, and stroke-dashoffset to shift the pattern.Add Labels with SVG Text
Next, learn how to render text, align it, and style it inside an SVG.
4 people found this page helpful
