Interactive online courses HTML Academy
2026-03-09 10:48 Diff

You can draw lines using the linetag. The coordinates of the beginning of the line are specified using the attributes x1 andy1, whereas the coordinates for the end of the line are assigned using the attributes x2 andy2. Coordinates can be specified as a percentage.

Code example:

<line x1="220" y1="10" x2="20" y2="130"/>

Since the line does not form a shape with an inner contour, it should not be set as a shape with a fill color, but as a stroke in order to be displayed. Two attributes are used to control a stroke: stroke and stroke-width. The stroke attribute is used to set the stroke color, and stroke-width is used to set the line width.

<line x1="220" y1="20" x2="20" y2="90" stroke="violet" stroke-width="5" />

Result:

You can only set the line color. The default stroke thickness will be equal to one pixel.