Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SVG Polyline

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:

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

The element is used to create any shape that has only straight lines:

Sorry, your browser does not support inline SVG.

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:

Sorry, your browser does not support inline SVG.

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.