SVG Polyline
In SVG, the The element is used to draw polylines; it is one of the commonly used basic shapes in SVG.
The difference between Unlike the element, the lines drawn are not closed, meaning the start and end points are not automatically connected. Using the element you can create multiple connected line segments, and control the vertex coordinates, fill color, border color, etc. of the segments by setting attributes.
Basic Syntax
fill="none"
stroke="stroke-color"
stroke-width="width"
/>
Attribute Analysis:
-
pointsThe attribute defines the coordinates of each vertex of the polyline; multiple vertex coordinates are separated by spaces or commas, and each pair of coordinates is separated by a comma. -
fillThe attribute is used to define the fill color of the polyline, usually set to "none" to indicate no fill. -
strokeThe attribute defines the border color of the polyline. -
stroke-widthThe attribute defines the border width of the polyline.
The following code draws a polyline with a black stroke and a width of 2 pixels; its vertex coordinates are (50, 50), (100, 150), (150, 100), and (200, 200), forming multiple connected line segments.
Example 1
Below is the SVG code:
Example
<
svg
xmlns
=
"
http://www.w3.org/2000/svg
"
version
=
"
1.1
"
<
polyline
points
=
"20,20 40,25 60,40 80,120 120,140 200,180
"
style
=
"
fill:none;stroke:black;stroke-width:3
"
/>
svg
Try it »
Click to view:View SVG File.
Example 2
Another example with only straight lines:
Below is the SVG code:
Example
<
svg
xmlns
=
"
http://www.w3.org/2000/svg
"
version
=
"
1.1
"
<
polyline
points
=
"0,40 40,40 40,80 80,80 80,120 120,120 120,160
"
style
=
"
fill:white;stroke:red;stroke-width:4
"
/>
svg
Try it »
Click to view:View SVG File.