HTML SVG <polygon>

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

Definition and Usage

The SVG <polygon> element draws a closed shape from connected straight segments. You list vertices in points; the browser connects the last point back to the first.

For an open chain of segments, use <polyline>. For curves, use <path>.

Baseline · Widely available.

<polygon> is a stable SVG basic shape across modern browsers since about July 2015.

Auto-closes.

You do not need to repeat the first coordinate at the end — closing is built in.

Need three or more points.

Fewer than three valid vertices cannot form a filled polygon. Check commas and spaces in points.

Syntax

polygon.html
<svg width="200" height="160" viewBox="0 0 200 160"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Filled triangle polygon">
  <polygon points="100,20 40,140 160,140"
           fill="#2563eb" stroke="#0f172a" stroke-width="3" />
</svg>

Pattern: list x,y pairs in order around the shape, then style with fill/stroke.

Attributes

Core <polygon> attributes:

AttributeDescriptionTry it
pointsList of x,y vertices (required)Try it
fillInterior paintTry it
stroke / stroke-widthOutline color and thicknessTry it
stroke-linejoinCorner style: miter, round, bevelTry it
pathLengthOptional path length for dash mathTry it

Global Attributes

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

Live Preview

Switch closed shapes and toggle fill. The stroke stays on so outlines remain visible.

Last point closes automatically to the first.

SVG

points="100,20 40,140 160,140"

HTML Examples

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

Example 1 — Filled Triangle

Three points form the simplest closed polygon.

HTML
<svg width="200" height="160" viewBox="0 0 200 160"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Filled triangle polygon">
  <polygon points="100,20 40,140 160,140"
           fill="#2563eb" stroke="#0f172a" stroke-width="3" />
</svg>
Try It Yourself

How It Works

  1. List three x,y points in order.
  2. The browser closes the last side for you.
  3. Set fill for the interior.
  4. Add stroke to outline the edges.

Example 2 — Stroke Only

Use fill="none" for a wireframe polygon.

HTML
<svg width="200" height="160" viewBox="0 0 200 160"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Outlined triangle polygon">
  <polygon points="100,20 40,140 160,140"
           fill="none" stroke="#16a34a" stroke-width="4"
           stroke-linejoin="round" />
</svg>
Try It Yourself

How It Works

  1. fill="none" leaves the interior empty.
  2. stroke draws the closed outline.
  3. stroke-linejoin="round" softens corners.
  4. Same points as a filled triangle.

Example 3 — Diamond

Four points make a diamond (rotated square).

HTML
<svg width="200" height="180" viewBox="0 0 200 180"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Diamond polygon">
  <polygon points="100,20 170,90 100,160 30,90"
           fill="#7c3aed" stroke="#0f172a" stroke-width="3" />
</svg>
Try It Yourself

How It Works

  1. Order points around the diamond (top → right → bottom → left).
  2. Keep spacing even for a regular look.
  3. Closing is automatic from left back to top.
  4. Prefer <rect> + rotate only if a true square is easier.

Example 4 — Hexagon

Six vertices create a regular-looking hexagon.

HTML
<svg width="220" height="180" viewBox="0 0 220 180"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Hexagon polygon">
  <polygon points="110,20 180,55 180,125 110,160 40,125 40,55"
           fill="#16a34a" stroke="#0f172a" stroke-width="3" />
</svg>
Try It Yourself

How It Works

  1. List six points in clockwise (or counter-clockwise) order.
  2. Match opposite sides for a regular hex look.
  3. Fill and stroke work the same as simpler polygons.
  4. Great for badges and map-style tiles.

Example 5 — Five-Point Star

Alternate outer and inner points in one points list.

HTML
<svg width="200" height="190" viewBox="0 0 200 190"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Five-point star polygon">
  <polygon
    points="100,15 118,70 178,70 130,105 148,160 100,128 52,160 70,105 22,70 82,70"
    fill="#facc15" stroke="#0f172a" stroke-width="2"
    stroke-linejoin="round" />
</svg>
Try It Yourself

How It Works

  1. Alternate tip and indent coordinates around the center.
  2. Self-intersections are allowed — that is how the star fills.
  3. Round joins keep sharp tips cleaner when stroked.
  4. For complex stars, generating points with a small script helps.

Edge Cases & Pitfalls

Most broken polygons are bad points strings or missing paint.

points

Malformed point lists

Keep clear x,y pairs. Odd counts or missing commas/spaces can drop the shape.

viewBox

Vertices outside the box

If all points sit outside the viewBox, the polygon is clipped or invisible.

open

Want an open shape?

Use <polyline>. Polygon always closes.

paint

fill none needs stroke

Wireframe polygons need a visible stroke or they disappear.

Browser Support

The SVG <polygon> element is supported in every modern browser.

✓ Baseline · Widely available

SVG <polygon>

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support polygon points and presentation attributes. Internet Explorer 9+ supports basic SVG polygons.

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
<polygon> Widely supported

Bottom line: Safe for production icons, charts, and badges. Keep points readable with spaces between pairs.

Key Takeaways

  • points lists the vertices.
  • Always closed — last connects to first.
  • Paint with fill and/or stroke.
  • Open shape? Use polyline; curves? use path.

One line: ordered points + fill/stroke inside an <svg>.

Default CSS Settings

Conceptual SVG presentation defaults for polygons:

defaults.css
/* Conceptual SVG defaults */
polygon {
  fill: black;
  stroke: none;
  stroke-width: 1;
  stroke-linejoin: miter;
}

Set fill and stroke explicitly so demos stay predictable across contexts.

Frequently Asked Questions

Use <polygon> with a points list of x,y pairs. The browser closes the shape by connecting the last point to the first.
A list of coordinate pairs such as "10,10 50,10 50,50". Spaces (or commas) separate points.
polygon is closed automatically. polyline stays open unless you repeat the first point yourself.
Points may be outside the viewBox, fill is none with no stroke, or the points string is malformed.
Use path when you need curves or mixed commands. Prefer polygon for closed straight-sided shapes.
Yes. Set fill, stroke, and stroke-width via attributes or CSS selectors.

Next: SVG Polyline

Learn open multi-segment lines with the same points idea.

SVG Polyline →

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