In SVG (Scalable Vector Graphics), a polyline is a shape element that defines a series of connected straight line segments. The <polyline> element is used to create these multi-segmented lines. Each point in the polyline is specified by an (x, y) coordinate pair.

Here's the basic structure of a <polyline> element:

xml
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <polyline points="x1,y1 x2,y2 x3,y3 ..." /> </svg>

Let's break down the key components:

  • <polyline>: This is the SVG element for creating polylines.
  • points: This attribute defines the coordinates of the polyline. The coordinates are specified as a space-separated list of (x, y) pairs.

Now, let's look at some examples:

Example 1: Simple Polyline

xml
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <polyline points="10,10 50,10 50,50 10,50 10,10" stroke="black" fill="none" /> </svg>

This example creates a square with vertices at (10,10), (50,10), (50,50), and (10,50).

Example 2: Open Polyline with Styling

xml
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <polyline points="10,10 50,10 90,50 50,90 10,90" stroke="blue" fill="none" stroke-width="2" /> </svg>

This example creates an open polyline with vertices at (10,10), (50,10), (90,50), (50,90), and (10,90). The polyline is styled with a blue stroke and a stroke width of 2.

Example 3: Closed Polyline with Fill

xml
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <polyline points="10,10 50,10 90,50 50,90 10,90" stroke="green" fill="lime" stroke-width="2" /> </svg>

This example creates a closed polyline with the same vertices as Example 2. The polyline has a green stroke, a lime fill, and a stroke width of 2.

Example 4: Diagonal Polyline

xml
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <polyline points="10,10 50,50 90,90" stroke="red" fill="none" stroke-width="2" /> </svg>

This example creates a diagonal polyline with vertices at (10,10), (50,50), and (90,90). The polyline has a red stroke and a stroke width of 2.

Feel free to modify the coordinates, stroke, fill, and other attributes to customize the appearance of your polylines.