HTML SVG <polyline>

Beginner
8 min read
Updated: Nov 2026
5 examples
Live preview

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

polyline.html
<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.

Attributes

Core <polyline> attributes:

AttributeDescriptionTry it
pointsList of x,y vertices (required)Try it
fillUsually none for open linesTry it
stroke / stroke-widthLine color and thicknessTry it
stroke-linecap / stroke-linejoinEnd and corner stylesTry it
stroke-dasharrayDash and gap patternTry it
pathLengthOptional length for dash mathTry it

Global Attributes

The <polyline> tag also supports the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.

Live Preview

Switch open shapes and change stroke width. Fill stays off for a clear line.

4

Unlike polygon, the first and last points stay disconnected.

SVG

points="20,90 70,30 120,90 170,30 220,90"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Zig-Zag

Connect several points with a stroked open line.

HTML
<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>
Try It Yourself

How It Works

  1. List x,y points in drawing order.
  2. Set fill="none" so only the stroke shows.
  3. Add stroke and stroke-width.
  4. Round caps/joins soften corners.

Example 2 — Line Joins

Compare corner styles on the same points.

HTML
<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>
Try It Yourself

How It Works

  1. Same points on both polylines.
  2. miter keeps sharp corners.
  3. round softens each join.
  4. Offset one copy so you can compare clearly.

Example 3 — Dashed Polyline

Use stroke-dasharray for a dashed open line.

HTML
<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>
Try It Yourself

How It Works

  1. Draw a normal stroked polyline.
  2. stroke-dasharray="12 10" means 12 on, 10 off.
  3. Round caps soften each dash end.
  4. See also the SVG stroke page.

Example 4 — Simple Chart Line

Axes from lines plus a polyline for data.

HTML
<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>
Try It Yourself

How It Works

  1. Draw axes with <line>.
  2. Map each data value to an x,y point.
  3. Connect them with one polyline.
  4. Keep fill none so it stays a chart line.

Example 5 — Manually Closed Polyline

Repeat the first point to close — or just use polygon.

HTML
<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>
Try It Yourself

How It Works

  1. Repeat the start point at the end of points.
  2. The outline closes, but this is still a polyline.
  3. Prefer <polygon> for filled closed shapes.
  4. 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.

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.

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).

Default CSS Settings

Conceptual SVG presentation defaults for polylines:

defaults.css
/* 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

Use <polyline> with a points list of x,y pairs, then set stroke and stroke-width. Usually also set fill="none".
A list of coordinate pairs such as "10,10 50,10 50,50". Spaces separate points.
polyline stays open. polygon closes by connecting the last point to the first.
It needs a visible stroke. Missing stroke or stroke-width 0 hides it. Also check the viewBox.
Default fill can paint an unexpected area. Prefer fill="none" for open charts/lines, or use polygon for closed fills.
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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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