SVG Polyline

What You’ll Learn
The SVG <polyline> element draws a series of straight line segments by connecting multiple points. It’s ideal for charts, zig-zags, connectors, and custom line shapes.
You’ll learn how the points attribute works, how to style polylines with stroke properties, and how polylines differ from polygons.
⚡ Quick Reference — SVG Polyline
Element
<polyline>An open multi-point line
Points
pointsSpace-separated x,y pairs
Stroke
strokeRequired to see the line
Stroke width
stroke-widthThickness in pixels
Dash pattern
stroke-dasharrayDashed or dotted polylines
Basic Syntax
<svg>
<polyline points="x1,y1 x2,y2 x3,y3" fill="none" stroke="black" />
</svg>👀 Live Preview — Common Polylines
Polylines are perfect for charts and zig-zag connectors.
Zig-zag
Polyline chart
Dashed connector
1
Complete HTML Example
This example draws a 5-point polyline and styles it with a black stroke. (A polyline is open, so we use fill="none".)
index.html
<!DOCTYPE html>
<html>
<body>
<svg width="200" height="200">
<polyline points="50,50 100,25 150,50 125,100 75,100"
fill="none" stroke="black" stroke-width="2" />
</svg>
</body>
</html>💡 Best Practices
Do
- Always set a visible
stroke(polylines have no fill area by default) - Use
stroke-linecapandstroke-linejoinfor nicer corners - Keep point lists readable with consistent spacing
- Use a
viewBoxfor responsive charts and connectors - Use
stroke-dasharrayfor dashed connectors
Don’t
- Assume a polyline is closed (it stays open unless you close it)
- Use
fillexpecting a closed shape—use<polygon>instead - Forget to keep points inside the SVG viewBox/canvas
- Overuse too many points when a simpler shape works
- Skip accessibility labels for meaningful charts or UI connectors
❓ Frequently Asked Questions
Use
<polyline> and provide a points list of x,y pairs. Style it with stroke and stroke-width.points is a list like "10,10 50,10 50,50". Each pair is x,y and pairs are separated by spaces.A polyline is open and does not close automatically. A polygon is closed and connects the last point back to the first.
Polylines need a visible
stroke. Also check that the points are inside the viewBox and that stroke-width is not zero.Usually no—polylines are open. If you want a filled closed shape, use
<polygon>. If you really need fill, repeat the first point at the end to close the outline.Add Depth with Radial Gradients
Next, learn how to create radial gradients for highlights, glows, and modern UI fills.
4 people found this page helpful
