<polyline>
Core element
Place <polyline> inside an <svg> to draw connected segments.

SVG’s <polyline> draws an open chain of straight segments by connecting multiple points. This tutorial covers the points attribute, stroke styling (stroke, stroke-width, stroke-linecap, stroke-linejoin, stroke-dasharray), responsive viewBox usage, five worked examples, and how <polyline> compares to <polygon>, <line>, and <path>.
Core element
Place <polyline> inside an <svg> to draw connected segments.
Vertex list
Space-separated x,y pairs define each corner of the path.
Not closed
Unlike <polygon>, the last point does not connect back to the first.
Required paint
Polylines have no fill area — set stroke and stroke-width to see them.
linecap / linejoin
Round or bevel corners and end caps for smoother polylines.
Responsive
Scale chart lines and connectors cleanly with a viewBox and CSS sizing.
SVG’s <polyline> connects a series of straight segments through a list of points. It powers line charts, zig-zag connectors, route paths, and custom stroke shapes that are not closed.
Like <line>, a polyline has no meaningful fill area when open. Visibility comes entirely from presentation attributes like stroke and stroke-width — forget those and nothing appears.
One element replaces many stacked <line> tags. Polylines stay sharp at any zoom, animate cleanly, and style with the same stroke tools as other SVG shapes.
A flat points attribute defines every vertex in order.
Use fill="none" — colour and thickness come from stroke attributes.
Control ends with stroke-linecap and corners with stroke-linejoin.
One drawing scales to any CSS size without rewriting points.
In short: list your points, set fill="none", then paint the stroke — that’s the foundation of SVG polylines.
Basic form of the SVG polyline element:
<svg width="200" height="200">
<polyline points="50,50 100,25 150,50"
fill="none" stroke="black" stroke-width="2" />
</svg> | Attribute | Type | Description |
|---|---|---|
points | List | Space-separated x,y pairs for each vertex. Required. |
fill | Paint | Usually none for open polylines. |
stroke | Paint | Line colour — required for the polyline to be visible. |
stroke-width | Length / number | Thickness of the stroke in user units. |
stroke-linecap | Keyword | butt, round, or square end caps. |
stroke-linejoin | Keyword | miter, round, or bevel at corners. |
stroke-dasharray | List | Dash and gap lengths for dashed or dotted polylines. |
| Result | Details |
|---|---|
| open polyline | Renders a connected chain of straight segments through the listed points — the path stays open. |
<svg width="200" height="200" viewBox="0 0 200 200">
<polyline points="50,50 100,25 150,50 125,100 75,100"
fill="none" stroke="#0f172a" stroke-width="2" />
</svg> | Idea | Detail | Notes |
|---|---|---|
| Origin | (0, 0) is top-left | y grows downward |
| Visibility | Needs stroke | stroke-width of 0 hides it |
| Minimum points | Two x,y pairs | One pair is a dot; two pairs draw one segment |
| Closed shape | Repeat first point | Or use <polygon> instead |
| Goal | Code |
|---|---|
| Basic polyline | <polyline points="50,50 100,25 150,50" fill="none" stroke="#0f172a" stroke-width="2" /> |
| Thick stroke | stroke-width="6" |
| Rounded ends & corners | stroke-linecap="round" stroke-linejoin="round" |
| Dashed polyline | stroke-dasharray="8 6" |
| Chart with dots | Polyline + <circle> at each vertex |
| Responsive SVG | <svg viewBox="0 0 200 200">... + CSS width |
<polyline> vs <polygon> vs <line> vs <path>All can create edges — pick the simplest element that fits.
open chainConnected straight segments through a points list
closed shapeAuto-closes — last point connects to first
one segmentSingle straight stroke between two points
any shapeCurves, arcs, and mixed commands — most flexible
<polyline>Reach for <polyline> whenever you need multiple connected straight segments in one element.
Plot data trends by connecting values with straight segments.
Route lines around obstacles in diagrams and UI flows.
Multi-segment links between nodes in flow charts.
Annotation lines, cut lines, and temporary paths.
A single straight edge is simpler with <line>.
Key benefit: one element, one points list — the lightest multi-segment stroke in SVG.
Five starter snippets using <polyline>. Click View Output for a preview, or Try It Yourself to edit live.
Draw a five-point polyline, then style corners and caps.
Draw a five-point open shape inside a 200×200 canvas. Use fill="none" because the path stays open.
<svg width="200" height="200">
<polyline points="50,50 100,25 150,50 125,100 75,100"
fill="none" stroke="#0f172a" stroke-width="2" />
</svg> Each x,y pair is a vertex. The browser connects them in order with straight segments. Without stroke, the polyline is invisible.
Add stroke-linecap="round" and stroke-linejoin="round" for smoother zig-zag connectors.
<svg width="220" height="80">
<polyline points="10,50 50,20 90,50 130,20 170,50 210,30"
fill="none" stroke="#3b82f6" stroke-width="4"
stroke-linecap="round" stroke-linejoin="round" />
</svg> stroke-linecap rounds the open ends, and stroke-linejoin rounds the corners where segments meet — ideal for friendly UI connectors.
Charts, dashed connectors, and responsive sizing.
Draw a trend line and add <circle> elements at each vertex to mark data points.
<svg width="220" height="100" viewBox="0 0 220 100">
<polyline points="20,70 55,55 90,62 125,35 160,42 195,22"
fill="none" stroke="#10b981" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round" />
<circle cx="20" cy="70" r="4" fill="#10b981" />
<circle cx="55" cy="55" r="4" fill="#10b981" />
<circle cx="90" cy="62" r="4" fill="#10b981" />
<circle cx="125" cy="35" r="4" fill="#10b981" />
<circle cx="160" cy="42" r="4" fill="#10b981" />
<circle cx="195" cy="22" r="4" fill="#10b981" />
</svg> The polyline draws the trend; circles highlight each sample. In real charts you might generate both from the same data array.
Use stroke-dasharray for dashed annotation lines and multi-segment connectors.
<svg width="220" height="80">
<polyline points="10,20 70,20 70,60 200,60"
fill="none" stroke="#b45309" stroke-width="4"
stroke-linecap="round" stroke-linejoin="round"
stroke-dasharray="8 6" />
</svg> 8 6 means 8 units on, 6 off along the entire path — including corners. Round joins keep dashes smooth at bends.
Define coordinates in a viewBox, then let CSS control the displayed size.
<style>
.chart-line { width: 180px; height: auto; display: block; }
</style>
<svg class="chart-line" viewBox="0 0 160 48"
role="img" aria-label="Responsive trend line">
<polyline points="12,34 38,28 64,32 90,18 116,22 142,12"
fill="none" stroke="#2563eb" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round" />
</svg> The viewBox maps user units to whatever CSS size you give the SVG. Change .chart-line { width } and the polyline scales without rewriting points.
Real-world places where SVG polylines show up every day.
Trend lines connecting data values over time.
Example: stock price or analytics sparkline.
Connectors that bend around layout obstacles.
Example: cable path in a diagram.
Multi-segment links between process nodes.
Example: L-shaped connector between boxes.
Dashed guides, cut lines, and callout stems.
Example: dashed leader to a label.
Multi-segment strokes in custom icons.
Example: lightning bolt or mountain outline.
Geometry demos showing connected vertices.
Example: interactive point-to-point paths.
Pro Tip: for a closed filled shape, switch to <polygon> instead of repeating the first point on a polyline.
Why draw multi-segment paths with SVG polylines.
Replace stacks of <line> tags with a single points list.
Stays sharp on retina screens without extra assets.
Caps, joins, dashes, and colours via attributes or CSS.
A flat points string is easy to read and generate from data.
Animate stroke-dashoffset for draw-on path effects.
Pro Tip: for UI icons, stroke="currentColor" lets polylines inherit the parent text colour for theming.
Follow these practices for clean, scalable SVG polylines.
Polylines are invisible without stroke and a positive stroke-width.
Open polylines have no interior — set fill="none" explicitly.
stroke-linejoin="round" softens sharp corners on trend lines.
Use consistent spacing in the points string for easier debugging.
Define geometry once, then size the SVG with CSS.
Pro Tip: generate the points string from JavaScript when plotting live data — one template handles any number of vertices.
Avoid these mistakes when your polyline refuses to show up.
strokeA polyline with no stroke paint is invisible.
→ Always set stroke and a non-zero stroke-width.
<polyline> stays open — unlike <polygon>.
→ Use <polygon> for closed shapes, or repeat the first point.
Vertices outside the canvas get clipped or disappear.
→ Keep all points inside the SVG size or viewBox.
Missing commas or odd numbers break the coordinate pairs.
→ Each point must be x,y with pairs separated by spaces.
A two-point polyline works, but <line> is simpler.
→ Prefer <line> for a single straight edge.
Pro Tip: if a polyline vanishes, check stroke, stroke-width, and whether all points sit inside the viewBox — those three catch most issues.
<polyline> Is DrawnSet points to space-separated x,y pairs — each pair is a vertex on the canvas.
The browser draws straight lines from the first point to the second, then to the third, and so on — the path stays open.
Open polylines have no interior area. Use fill="none" so only the stroke renders.
Set stroke and stroke-width. Style caps, joins, and dashes as needed.
The browser draws the vector live from your points and stroke paint — sharp at every zoom level.
<polyline> needs stroke — there is no fill area on an open path.stroke-linejoin values: miter, round, bevel.stroke-dasharray creates dashed and dotted polylines.<polygon>.viewBox when chart lines must scale responsively.Quick Takeaway: points list + fill="none" + stroke paint. Keep vertices inside the viewBox, and use CSS sizing for responsive charts.
The SVG <polyline> element is supported in all modern browsers — and has been for many years — as part of SVG 1.1 basic shapes.
Use
Bottom line: Safe for production sites. Prefer inline SVG or cached .svg assets; no polyfill is required for current browsers.
SVG <polyline> is the go-to element for open multi-segment strokes: list your points, set fill="none", then paint with stroke and stroke-width.
Practice the five examples above, then continue to SVG Path when you need curves, arcs, and the full drawing command set.
Always set a stroke, use round joins for charts, and pair with viewBox when the line must scale with the layout.
stroke on <polyline> elementsfill="none" for open pathsstroke-linejoin="round" for smoother chart linespoints from data for dynamic chartsviewBox when the graphic must scalestroke and wonder why nothing appears<polygon>fill expecting a closed shape area<line> tags when one polyline would do<polyline>Draw connected segments the SVG way.
Open multi-segment path
APISpace-separated x,y pairs
GeometryRequired to see it
Paintlinecap & linejoin
StyleScales cleanly
ResponsiveAn SVG <polyline> is an open chain of connected straight segments — it does not auto-close like <polygon>. Without stroke (and a non-zero stroke-width), the polyline is invisible. You can animate stroke-dashoffset on a polyline to create draw-on path effects — popular for chart reveals and signature animations.
Learn how the d attribute unlocks curves, arcs, and any shape you can imagine.
8 people found this page helpful