Lesson 5
Objective: Learn to draw, position and style a line.
<line x1="0" y1="0" x2="100" y2="100"></line>
<line> ... </line> The full line element with open and closing tags.
<line /> Because this does not contain any content it can also be used as a self-closing element.
The line has four layout attributes you must know and remember:
x1 The line starting x coordinate.
y1 The line starting g coordinate.
x2 The line ending x coordinate.
y2 The line ending y coordinate.
The same style properties apply except line does not need to use fill.
Lines look simple but they have a number of presentation styles that are very useful in many illustration contexts. Note that these stroke- properties can be used on the stroke of all shapes and not just lines.
stroke-linecap="butt" The value can also be round or square. The default value if you do not specify stroke-linecap is butt.
stroke-dasharray="5, 10" This property allows a dashed line with different spacing to be created. Any number of values can be used but they MUST be separated by commas.
You can use these properties on any shape, not just <line />.
This first example uses full SVG attributes to define the stroke colour and size of the line.
<line x1="100" y1="200" x2="300" y2="200" stroke="black" stroke-width="5"> </line>
<line x1="200" y1="10" x2="200" y2="390" stroke-linecap="butt" stroke-dasharray="10,5" stroke="green" stroke-width="10"> </line>
Here is the SVG for those who are too lazy to type the SVG. View the SVG Markup
Here are our standard SVG Cheatsheets you can download, print out and have ready when needed. There is also a text file containing annotated quickstarts for all major shapes and techniques.
SVG Editor. Access a full SVG Editor online at any time.