The <line> element
defines a straight line by defining the starting (x1,y1)
and the
ending points (x2, y2)
The <polyline> element is
used to create any shape that consists of only straight
lines. It has the same attributes as <polygon>, except
that the shape is not closed. The last point in the <polyline>
element is the end of the shape. If you want to close a
polyline, you must manually add a point at the end equal
to the starting point.
Code Example
SVG Image
<?xml version="1.0"
standalone="no"?>
Right-click
on the image to open the SVG viewer pop-up menu. Click
'view SVG' to display the image in a new, full window
to zoom & pan the image.
(SVG Viewer Tips)
<!DOCTYPE svg PUBLIC
"-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg
width="200" height="500">
<!-- A horizontal line -->
<line x1="40" y1="20"
x2="80" y2="20" style="stroke:
blue; ; stroke-width: 2"/>
<!-- A vertical line -->
<line x1="0.7cm"
y1="1cm" x2="0.7cm" y2="2.0cm"
style="stroke: red; ; stroke-width: 4"/>
<!-- A diagonal line -->
<line x1="30" y1="30"
x2="85" y2="85" style="stroke:
green; ; stroke-width: 6"/>
The <line> element draws
a straight line segment at the coordinates supplied
in the x1 and y1 attributes, and ends the line at
the coordinates supplied in the x2 and y2 attributes.
Lines can be drawn from different direction and with
different thickness by using the stroke-width
property.
In the <polyline> example, the numbers
in the points attribute refer to xy coordinates. The
first number (5,190) is the starting point, and straight
line segments are drawn to each successive point.
The <polyline> ends with the point
defined by the last pair of xy coordinate numbers
(95,190).
You may specify the shape of the endpoints of the
lines by setting the stroke-linecap property
to one of the values "butt", "round",
or "square". The third diagram shows these
three values, with gray guide lines showing the actual
endpoints of the lines. You can see that "round"
and "square" extend beyond the end coordinates;
"butt", the default, ends exactly at the
specified endpoint.
You may also specify the way lines connect at the
corners of a shape with the stroke-linejoin property,
which may have the values "miter" (pointed),
"round" , or "bevel" (flat) like
the ones in the last example.