<line>

The <line> element is an SVG basic shape used to create a line connecting two points.

Usage context

CategoriesBasic shape element, Graphics element, Shape element
Permitted contentAny number of the following elements, in any order:
Animation elements
Descriptive elements

Attributes

Global attributes

Specific attributes

DOM Interface

This element implements the SVGLineElement interface.

Examples

Diagonal line using attributes

SVG

<svg width="120" height="120" viewBox="0 0 120 120"
    xmlns="http://www.w3.org/2000/svg">
  <line x1="20" y1="100" x2="100" y2="20"
      stroke-width="2" stroke="black"/>
</svg>

Result

Diagonal line using a transformation

You can also apply a transformation to get the same result. Beginning with a normal line and then adding the transformation options to change the direction of the line.

SVG

<svg width="120" height="120" viewBox="0 0 120 120"
    xmlns="http://www.w3.org/2000/svg">
  <line x1="20" y1="100" x2="100" y2="100"
      stroke-width="2" stroke="black" transform="rotate(-45 20 100)"/>
</svg>

Result

Specifications

Specification Status Comment
Scalable Vector Graphics (SVG) 2
The definition of '<line>' in that specification.
Candidate Recommendation Changed the x1, y1, x2 and y2 attributes to take <length>s, <percentage>s and <number>s
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of '<line>' in that specification.
Recommendation Initial definition

Browser compatibility

Feature Chrome Edge Firefox (Gecko) IE Opera Safari
Basic support 1.0 (Yes) 1.5 (1.8) 9.0 8.0 3.0.4
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 3.0 (Yes) 1.0 (1.8) No support (Yes) 3.0.4

The chart is based on these sources.

See also

Document Tags and Contributors

 Last updated by: abbycar,