Home SVG <polyline> HTML SVG <polyline> Definition
Definition and Usage The SVG <polyline> element draws an open chain of straight segments through a list of points. Unlike <polygon> , it does not connect the last point back to the first.
Use it for zig-zags, stairs, and simple chart lines. For one segment use <line> ; for curves use <path> .
Baseline · Widely available. <polyline> is a stable SVG basic shape across modern browsers since about July 2015.
Set fill="none" for open lines. Default fill can paint an unexpected closed area across the points. For stroke-only charts, always disable fill.
No stroke = often invisible. A polyline is usually a stroked outline. Without stroke (or with stroke-width 0), you may see nothing useful.
Syntax
Syntax <svg width="240" height="120" viewBox="0 0 240 120"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Open zig-zag polyline">
<polyline points="20,90 70,30 120,90 170,30 220,90"
fill="none" stroke="#2563eb" stroke-width="4"
stroke-linecap="round" stroke-linejoin="round" />
</svg> Pattern: ordered x,y pairs → fill="none" → visible stroke.
Reference
Attributes Core <polyline> attributes:
Attribute Description Try it pointsList of x,y vertices (required) Try itfillUsually none for open lines Try itstroke / stroke-widthLine color and thickness Try itstroke-linecap / stroke-linejoinEnd and corner styles Try itstroke-dasharrayDash and gap pattern Try itpathLengthOptional length for dash math Try it
Also supported
Global Attributes The <polyline> tag also supports the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.
Try it
Live Preview Switch open shapes and change stroke width. Fill stays off for a clear line.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Basic 2. Joins 3. Dashed 4. Chart 5. Manual close Example 1 — Basic Zig-Zag Connect several points with a stroked open line.
<svg width="240" height="120" viewBox="0 0 240 120"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Open zig-zag polyline">
<polyline points="20,90 70,30 120,90 170,30 220,90"
fill="none" stroke="#2563eb" stroke-width="4"
stroke-linecap="round" stroke-linejoin="round" />
</svg> How It Works List x,y points in drawing order.Set fill="none" so only the stroke shows.Add stroke and stroke-width .Round caps/joins soften corners.Example 2 — Line Joins Compare corner styles on the same points.
<svg width="240" height="160" viewBox="0 0 240 160"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Polylines with different linejoins">
<polyline points="20,40 80,120 140,40 200,120"
fill="none" stroke="#0f172a" stroke-width="10"
stroke-linejoin="miter" />
<polyline points="20,40 80,120 140,40 200,120"
fill="none" stroke="#2563eb" stroke-width="10"
stroke-linejoin="round" transform="translate(0 20)" />
</svg> How It Works Same points on both polylines.miter keeps sharp corners.round softens each join.Offset one copy so you can compare clearly.Example 3 — Dashed Polyline Use stroke-dasharray for a dashed open line.
<svg width="240" height="100" viewBox="0 0 240 100"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Dashed polyline">
<polyline points="20,70 80,30 140,70 200,30"
fill="none" stroke="#7c3aed" stroke-width="5"
stroke-linecap="round" stroke-dasharray="12 10" />
</svg> How It Works Draw a normal stroked polyline .stroke-dasharray="12 10" means 12 on, 10 off.Round caps soften each dash end.See also the SVG stroke page.Example 4 — Simple Chart Line Axes from lines plus a polyline for data.
<svg width="240" height="150" viewBox="0 0 240 150"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Chart axes with a data polyline">
<line x1="40" y1="20" x2="40" y2="120" stroke="#64748b" stroke-width="2" />
<line x1="40" y1="120" x2="220" y2="120" stroke="#64748b" stroke-width="2" />
<polyline points="40,100 80,70 120,85 160,45 200,55"
fill="none" stroke="#16a34a" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round" />
</svg> How It Works Draw axes with <line>.Map each data value to an x,y point.Connect them with one polyline.Keep fill none so it stays a chart line.Example 5 — Manually Closed Polyline Repeat the first point to close — or just use polygon.
<svg width="200" height="160" viewBox="0 0 200 160"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Manually closed polyline">
<!-- First point repeated at the end -->
<polyline points="100,20 40,140 160,140 100,20"
fill="none" stroke="#ea580c" stroke-width="4"
stroke-linejoin="round" />
</svg> How It Works Repeat the start point at the end of points.The outline closes , but this is still a polyline.Prefer <polygon> for filled closed shapes.Use this trick only when you must stay with polyline. Edge Cases & Pitfalls Most polyline bugs are unexpected fill, missing stroke, or wrong shape choice.
fill Surprise filled area Default fill can cover the space under the line. Use fill="none" for open charts.
stroke Stroke is required for a line look Without stroke, a polyline rarely looks like a connected line series.
close Does not auto-close Need a closed filled shape? Use <polygon> .
points Malformed point lists Keep clear x,y pairs. Odd counts or typos can drop segments.
Compatibility
Browser Support The SVG <polyline> element is supported in every modern browser.
✓ Baseline · Widely available
SVG <polyline> Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support polyline points and stroke styling. Internet Explorer 9+ supports basic SVG polylines.
98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer 9+
Supported <polyline> Widely supported
Bottom line: Safe for production chart lines and guides. Prefer fill="none" plus an explicit stroke in every example.
Remember
Key Takeaways points lists connected vertices.
Open by default — does not auto-close.
Use fill="none" + stroke for line charts.
Closed fill? Use polygon; curves? use path.
One line: ordered points + stroke (usually no fill).
UA style
Default CSS Settings Conceptual SVG presentation defaults for polylines:
/* Conceptual SVG defaults */
polyline {
fill: black; /* often unwanted for open lines */
stroke: none;
stroke-width: 1;
}
/* Typical teaching/demo style */
polyline.line {
fill: none;
stroke: currentColor;
} Always set fill="none" and an explicit stroke in beginner examples.
Frequently Asked Questions How do I draw a polyline in SVG? Use <polyline> with a points list of x,y pairs, then set stroke and stroke-width. Usually also set fill="none".
What format does points use? A list of coordinate pairs such as "10,10 50,10 50,50". Spaces separate points.
Polyline vs polygon? polyline stays open. polygon closes by connecting the last point to the first.
Why is my polyline invisible? It needs a visible stroke. Missing stroke or stroke-width 0 hides it. Also check the viewBox.
Can I fill a polyline? Default fill can paint an unexpected area. Prefer fill="none" for open charts/lines, or use polygon for closed fills.
When should I use line or path instead? Use line for one segment. Use path when you need curves. Use polyline for a chain of straight segments.
Next: SVG Path Learn d commands for curves, arcs, and closed icons.
SVG Path → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion