<polygon>
Core element
Place <polygon> inside an <svg> to draw a closed multi-sided shape.

SVG’s <polygon> draws closed shapes from a list of vertex coordinates. This tutorial covers the points attribute, fill and stroke styling, stroke-linejoin, responsive viewBox usage, five worked examples, and how <polygon> compares to <polyline>, <path>, and <rect>.
Core element
Place <polygon> inside an <svg> to draw a closed multi-sided shape.
Vertex list
Space-separated x,y pairs define each corner of the shape.
Closed path
The browser connects the last point back to the first — no repeat needed.
Interior paint
Set fill for the interior colour or pattern of the shape.
Outline
Add stroke and stroke-width for a visible border.
Responsive
Scale polygons cleanly with a viewBox and CSS sizing.
SVG’s <polygon> builds closed shapes from a flat list of coordinates — triangles, diamonds, hexagons, stars, and badges all start here. It powers icon glyphs, map regions, chart segments, and decorative UI elements.
Unlike <polyline>, a polygon always closes itself. The browser draws straight edges between consecutive points and connects the last vertex back to the first, giving you a fillable area.
Raster PNG icons blur when scaled. SVG polygons stay sharp, stay tiny in markup, and can be filled, stroked, and themed with CSS just like other vector shapes.
points="x1,y1 x2,y2 x3,y3" defines every vertex.
Last point connects to first — no duplicate coordinate needed.
Interior colour from fill; outline from stroke.
One drawing scales to any CSS size without rewriting points.
In short: list your corners in points, then paint with fill and stroke — the browser closes the shape for you.
Basic form of the SVG polygon element:
<svg width="200" height="200">
<polygon points="100,20 20,100 100,180 180,100"
fill="yellow" stroke="black" stroke-width="2" />
</svg> | Attribute | Type | Description |
|---|---|---|
points | List | Space-separated x,y pairs for each vertex. Required for a visible shape. |
fill | Paint | Interior colour. Defaults to black; use none for transparent fill. |
stroke | Paint | Outline colour around the polygon edges. |
stroke-width | Length / number | Thickness of the outline in user units. |
stroke-linejoin | Keyword | Corner shape: miter, round, or bevel. |
fill-rule | Keyword | nonzero or evenodd for self-intersecting shapes like stars. |
| Result | Details |
|---|---|
| closed polygon | Renders a closed shape by connecting consecutive points and closing back to the first. |
<svg width="200" height="200" viewBox="0 0 200 200">
<polygon points="100,30 40,170 160,170"
fill="#60a5fa" stroke="#1e3a8a" stroke-width="2" />
</svg> | Idea | Detail | Notes |
|---|---|---|
| Origin | (0, 0) is top-left | y grows downward |
| Separators | Spaces between points | "10,10 50,10 50,50" is standard |
| Minimum points | Three vertices | Two points make a line segment, not a filled area |
| Goal | Code |
|---|---|
| Basic triangle | <polygon points="100,30 40,170 160,170" fill="#60a5fa" /> |
| Diamond (4 points) | <polygon points="100,20 20,100 100,180 180,100" fill="yellow" stroke="black" stroke-width="2" /> |
| Stroke only | fill="none" stroke="#0f172a" stroke-width="2" |
| Rounded corners | stroke-linejoin="round" |
| Star fill rule | fill-rule="evenodd" |
| Responsive SVG | <svg viewBox="0 0 200 200">... + CSS width |
<polygon> vs <polyline> vs <path> vs <rect> vs <line>All can define edges — pick the simplest element that fits.
closed shapeStraight-sided closed shapes from a points list
open chainConnected segments that stay open unless you repeat the first point
any shapeCurves, arcs, and mixed commands — most flexible
axis-aligned boxRectangles with x, y, width, height — not arbitrary angles
one segmentSingle straight stroke — no fillable area
<polygon>Reach for <polygon> whenever you need a closed straight-sided shape defined by vertices.
Diamonds, chevrons, stars, and notification badges.
Triangles, pentagons, hexagons, and other regular polygons.
Pie slices, map regions, and labelled zones.
Play buttons, tooltips, speech-bubble tails, and arrows.
If you need arcs or Bézier curves, use <path>.
Key benefit: a flat list of points plus automatic closing — the lightest closed shape in SVG.
Five starter snippets using <polygon>. Click View Output for a preview, or Try It Yourself to edit live.
Draw a diamond and a styled triangle.
Create a diamond by placing four points around a centre — top, left, bottom, and right.
<svg width="200" height="200">
<polygon points="100,20 20,100 100,180 180,100"
fill="yellow" stroke="black" stroke-width="2" />
</svg> Four x,y pairs define the vertices. The browser draws edges between them and closes back to the first point automatically.
A three-point polygon with a blue fill, dark outline, and rounded corners via stroke-linejoin.
<svg width="200" height="200">
<polygon points="100,30 40,170 160,170"
fill="#60a5fa" stroke="#1e3a8a" stroke-width="3"
stroke-linejoin="round" />
</svg> Three points are enough for a closed triangle. stroke-linejoin="round" softens the corners where edges meet.
Regular polygons, stars, and stroke-only badges.
Six evenly spaced vertices around a centre create a flat-top hexagon — common in honeycomb layouts and game tiles.
<svg width="220" height="200" viewBox="0 0 220 200">
<polygon points="110,20 190,60 190,140 110,180 30,140 30,60"
fill="#a7f3d0" stroke="#047857" stroke-width="2"
stroke-linejoin="round" />
</svg> Six points at 60° intervals form a regular hexagon. A viewBox keeps the shape proportional when you resize the SVG.
Alternate outer and inner vertices to create a star. Use fill-rule="evenodd" for a clean centre cutout.
<svg width="200" height="200" viewBox="0 0 200 200">
<polygon points="100,15 123,75 188,75 136,115 158,180
100,140 42,180 64,115 12,75 77,75"
fill="#fbbf24" stroke="#b45309" stroke-width="2"
fill-rule="evenodd" stroke-linejoin="round" />
</svg> Ten alternating outer/inner points trace the star outline. Self-intersecting shapes often need fill-rule="evenodd" to fill correctly.
A six-point chevron with no fill — outline-only polygons work well for arrows and navigation icons.
<svg width="200" height="100" viewBox="0 0 200 100">
<polygon points="40,10 100,50 40,90 55,90 115,50 55,10"
fill="none" stroke="#22c55e" stroke-width="4"
stroke-linejoin="round" stroke-linecap="round" />
</svg> Set fill="none" and a visible stroke to draw outline-only shapes. Without a stroke, a transparent fill would be invisible.
Real-world places where SVG polygons show up every day.
Five-point stars for reviews and favourites.
Example: filled and outline star icons.
Back, forward, and dropdown arrow badges.
Example: breadcrumb or carousel chevrons.
Pie slices and radar chart facets.
Example: donut chart wedge from centre points.
Clickable country or zone outlines.
Example: choropleth map with hover fill.
Notification counts, labels, and tags.
Example: diamond sale badge on a product card.
Geometry lessons teaching vertices and angles.
Example: interactive triangle angle demos.
Pro Tip: for repeating tile fills inside polygons, pair with SVG Patterns.
Why draw closed shapes with SVG polygons instead of images or CSS hacks.
One points attribute defines the entire shape — no path commands to memorise.
Stays sharp on retina screens without extra assets.
Unlike lines, polygons create a closed region you can fill, pattern, or clip.
Triangles and badges in a single element — smaller than equivalent PNG icons.
Change fill, stroke, and hover states with CSS selectors.
Pro Tip: use fill="currentColor" so polygons inherit the parent text colour for theming.
Follow these practices for clean, scalable SVG polygons.
Use one space between x,y pairs — avoid inconsistent comma spacing.
stroke-linejoin="round" softens corners on triangles and stars.
Define geometry once, then size the SVG with CSS.
Self-intersecting shapes often need fill-rule="evenodd".
Polygons are for straight edges — switch to <path> when you need arcs.
Pro Tip: CSS classes on <polygon> keep fill and stroke consistent across an icon set.
Avoid these mistakes when your polygon refuses to show up.
fill="none" with no stroke makes the shape invisible.
→ Set a fill colour or a visible stroke.
Missing commas or odd separators break coordinate parsing.
→ Use consistent "x,y x,y x,y" formatting.
Vertices outside the canvas get clipped or disappear.
→ Keep all points inside the SVG size or viewBox.
Self-intersecting stars may fill the centre incorrectly.
→ Try fill-rule="evenodd" for star shapes.
Polygons always close — open chains need <polyline>.
→ Use <polyline> when the shape should stay open.
Pro Tip: if a polygon vanishes, check fill, stroke, and whether all points sit inside the viewBox — those three catch most issues.
<polygon> Is DrawnEach x,y pair in points marks a corner of the shape.
The browser draws straight edges from point to point in order.
The last point connects back to the first — you never repeat the starting coordinate.
Apply fill for the interior and stroke for the outline.
The browser renders the polygon live from vertices and paint — sharp at every zoom level.
<polygon> always closes — last point connects to first automatically.fill-rule="evenodd" helps self-intersecting stars fill correctly.<polyline> instead.viewBox when the graphic must scale responsively.Quick Takeaway: list corners in points, paint with fill and stroke. Keep vertices inside the viewBox, and use CSS sizing for responsive icons.
The SVG <polygon> 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 <polygon> turns a flat list of coordinates into closed, fillable shapes — triangles, diamonds, hexagons, stars, and badges.
Practice the five examples above, then continue to SVG Polyline when you need open multi-segment paths.
Remember auto-close behaviour, set visible fill or stroke, and use viewBox when the shape must scale with the layout.
points readable with consistent spacingstroke-linejoin="round" for nicer cornersfill-rule="evenodd" on self-intersecting starsviewBox when polygons must scale<path> for complex curvesfill="none" without a visible stroke<polygon>Draw closed shapes the SVG way.
Closed multi-sided shape
APIx,y vertex list
GeometryLast → first edge
PathInterior and outline
PaintScales cleanly
ResponsiveAn SVG <polygon> automatically closes the shape — the browser connects the last point back to the first, so you never repeat the starting coordinate. Unlike <polyline>, you never need to repeat the first point at the end of the list.
Learn how <polyline> draws open multi-segment paths with the same points syntax.
8 people found this page helpful