Home SVG <polygon> HTML SVG <polygon> Definition
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
Syntax <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.
Reference
Attributes Core <polygon> attributes:
Attribute Description Try it pointsList of x,y vertices (required) Try itfillInterior paint Try itstroke / stroke-widthOutline color and thickness Try itstroke-linejoinCorner style: miter, round, bevel Try itpathLengthOptional path length for dash math Try it
Also supported
Global Attributes The <polygon> 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 closed shapes and toggle fill. The stroke stays on so outlines remain visible.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Triangle 2. Stroke 3. Diamond 4. Hexagon 5. Star Example 1 — Filled Triangle Three points form the simplest closed polygon.
<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> How It Works List three x,y points in order.The browser closes the last side for you.Set fill for the interior.Add stroke to outline the edges.Example 2 — Stroke Only Use fill="none" for a wireframe polygon.
<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> How It Works fill="none" leaves the interior empty.stroke draws the closed outline.stroke-linejoin="round" softens corners.Same points as a filled triangle.Example 3 — Diamond Four points make a diamond (rotated square).
<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> How It Works Order points around the diamond (top → right → bottom → left).Keep spacing even for a regular look.Closing is automatic from left back to top.Prefer <rect> + rotate only if a true square is easier.Example 4 — Hexagon Six vertices create a regular-looking hexagon.
<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> How It Works List six points in clockwise (or counter-clockwise) order.Match opposite sides for a regular hex look.Fill and stroke work the same as simpler polygons.Great for badges and map-style tiles.Example 5 — Five-Point Star Alternate outer and inner points in one points list.
<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> How It Works Alternate tip and indent coordinates around the center.Self-intersections are allowed — that is how the star fills.Round joins keep sharp tips cleaner when stroked.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.
Compatibility
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.
Remember
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>.
UA style
Default CSS Settings Conceptual SVG presentation defaults for polygons:
/* 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 How do I draw a polygon in SVG? Use <polygon> with a points list of x,y pairs. The browser closes the shape by connecting the last point to the first.
What format does points use? A list of coordinate pairs such as "10,10 50,10 50,50". Spaces (or commas) separate points.
Polygon vs polyline? polygon is closed automatically. polyline stays open unless you repeat the first point yourself.
Why is my polygon invisible? Points may be outside the viewBox, fill is none with no stroke, or the points string is malformed.
When should I use path instead? Use path when you need curves or mixed commands. Prefer polygon for closed straight-sided shapes.
Can I style polygon with CSS? 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 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