SVG Line
In SVG, the The element is used to draw a straight line; it is one of the commonly used basic shapes in SVG.
Use The element can create a straight line between two points, and you can control the line's position, length, and style by setting attributes.
Basic Syntax
y1="y1-coordinate"
x2="x2-coordinate"
y2="y2-coordinate"
stroke="stroke-color"
stroke-width="width"
/>
Attribute analysis:
-
x1andy1The attribute defines the starting point coordinates of the line. -
x2andy2The attribute defines the ending point coordinates of the line. -
strokeThe attribute defines the color of the line. -
stroke-widthThe attribute defines the width of the line.
The following code draws a line with a black stroke and a width of 2 pixels, starting at (50, 50) and ending at (150, 150).
Example
Below is the SVG code:
Example
Try it »
Click to view:View SVG File.
- The x1 attribute defines the start of the line on the x-axis
- The y1 attribute defines the start of the line on the y-axis
- The x2 attribute defines the end of the line on the x-axis
- The y2 attribute defines the end of the line on the y-axis