SVG Polygon vs. Polyline: Check the Closing Edge
See why an SVG polyline can look filled while its closing stroke is missing. Compare it with a polygon using the same points, then check the edge in your file.
On this page
- Why a filled polyline can look closed
- Render the same points with and without fill
- Close the geometry when an edge is required
- FAQ
- Can a polyline have a fill?
- Does repeating the first point make a polyline equivalent to a polygon?
- Should I use fill-rule to fix a missing closing stroke?
- Start with editable artwork
- Sources
An SVG polygon connects its last point back to its first, so a visible stroke follows the closing edge. A polyline draws the segments between the points you list, so the stroke stops at the last point. A fill can still paint the space inside an open polyline. If a shape looks closed, turn off its fill and inspect the stroke. SVG 2 defines both basic shapes.
Why a filled polyline can look closed
The closing edge is the segment from the last point back to the first. SVG uses that segment to calculate the filled area even for an open polyline. The stroke follows the segments in the geometry, so it leaves the implicit fill edge unpainted. The SVG fill rules for open subpaths apply the same distinction to a <path> without a closepath command.
For a simple outline, decide by the edge you want to stroke. Use <polygon> for an enclosed badge or a straight-sided shape with a continuous border. Use <polyline> for an open chart trace, an angular route or any line that should end at the last point. Give an intentionally open line fill="none" to keep the interior clear.
Render the same points with and without fill
Save this example as closing-edge.svg and open it. Each shape uses the same four points and a six-unit teal stroke. The first and last points share x=22 in their local coordinates, so the prospective closing edge is the left side. The only artwork changes are the element name and the fill setting. The translations place the four copies next to each other.
<svg xmlns="http://www.w3.org/2000/svg" width="448" height="108"
viewBox="0 0 448 108">
<g stroke="#164b48" stroke-width="6" stroke-linecap="butt"
stroke-linejoin="miter">
<polygon points="22,20 86,20 98,62 22,66" fill="#edc565"/>
<polygon points="22,20 86,20 98,62 22,66" fill="none"
transform="translate(112 0)"/>
<polyline points="22,20 86,20 98,62 22,66" fill="#edc565"
transform="translate(224 0)"/>
<polyline points="22,20 86,20 98,62 22,66" fill="none"
transform="translate(336 0)"/>
</g>
<g fill="#164b48" font-family="sans-serif" font-size="12">
<text x="22" y="92">Fill + stroke</text>
<text x="134" y="92">Stroke only</text>
<text x="246" y="92">Fill + stroke</text>
<text x="358" y="92">Stroke only</text>
</g>
</svg>
We rendered the example with resvg 0.47.0 at one pixel per user unit. At local pixel (22, 42), halfway down the left edge, the result depended on the element and paint.
| SVG element | Gold fill and teal stroke | Teal stroke only |
|---|---|---|
| Polygon | Teal stroke | Teal stroke |
| Polyline | Gold fill | Transparent |
An interior sample at (56, 42) was the same opaque gold in both filled shapes. A sample on the existing top edge stayed teal in all four. To check an SVG of your own, open a copy and set the shape's fill to none while keeping its stroke visible. Inspect the gap between the first and last points. In a vector editor, an outline view or node inspection can show the endpoints too.
Close the geometry when an edge is required
If a straight-sided shape needs a joined border, change <polyline> to <polygon> and keep the same points. If the shape uses <path>, add Z at the end of the intended subpath. The SVG closepath specification explains how Z connects the final point to the start and joins the strokes at that corner. The relative path commands guide shows where the next command starts after a closepath.
Appending the first point to a polyline adds a return segment. The endpoints meet, and the stroke still applies an end cap to each. In our stroke-only test, appending 22,20 restored the left stroke. At local pixel (20, 18), just outside the upper-left corner, the polygon's miter join painted teal and the polyline's two butt caps left the pixel transparent.
The comparison tests a simple shape in one SVG renderer. For an export going to a plotter or cutter, confirm the actual geometry and run the receiving app's preview before sending it. If a single stroke turns into two visible contours after tracing, use the SVG double-cut diagnosis to check whether you have an outlined stroke or duplicate paths.
FAQ
Can a polyline have a fill?
Yes. SVG calculates the fill as if it joined the last point to the first. With an open polyline, the fill can reach that boundary even though its stroke ends at the last listed point.
Does repeating the first point make a polyline equivalent to a polygon?
Repeating the first point draws the return segment. The first and last stroke ends still use caps, so the corner can render differently from the joined corner on a polygon.
Should I use fill-rule to fix a missing closing stroke?
Use a polygon or a closed path if the last edge should be part of the stroke. The fill rule only controls which areas count as inside the shape.
Start with editable artwork
PerfectVector can recover editable SVG paths when a logo or filled silhouette exists only as a raster image. Vectorize the source PNG or JPG, then inspect its outline and openings in an editor before changing the closing edges. Use your existing SVG directly when its geometry is already editable.
Sources
- W3C — SVG 2 basic shapes — Defines polygon closure and the segments in a polyline.
- W3C — SVG 2 fill property — Defines how fill treats an open subpath.
- W3C — SVG 2 closepath command — Explains how closing a path joins strokes and how coincident endpoints retain caps on an open path.
More from the blog
How to Flatten SVG Transforms and Keep Path Shape
Rewrite SVG path coordinates to flatten nested transforms. Check the original and flattened artwork at the same scale and keep a separate master for edits.
Inkscape Object to Path vs Stroke to Path: What Changes?
Compare Inkscape Object to Path and Stroke to Path on the same circle. Learn which keeps a live stroke, which makes a filled band, and what to check next.


