Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

SVG <line>


SVG Line - <line>

The <line> element is used to create a line.

The <line> element creates a line between the start position (x1,y1) and the end position (x2,y2).

The <line> element has four basic attributes to position and set the length of the line:

Attribute Description
x1 The start of the line on the x-axis
y1 The start of the line on the y-axis
x2 The end of the line on the x-axis
y2 The end of the line on the y-axis

An SVG Line

The following example creates a line from position (0,0) to (300,200):

Sorry, your browser does not support inline SVG.

Here is the SVG code:

Example

<svg height="200" width="300" xmlns="http://www.w3.org/2000/svg">
  <line x1="0" y1="0" x2="300" y2="200" style="stroke:red;stroke-width:2" />
</svg>
Try it Yourself »

Code explanation:

  • The <x1> and <y1> attributes define the start of the line (0,0)
  • The <x2> and <y2> attributes define the end of the line (300,200)


A Horizontal Line

The following example creates a thick horizontal line from position (0,10) to (250,10):

Sorry, your browser does not support inline SVG.

Here is the SVG code:

Example

<svg height="50" width="300" xmlns="http://www.w3.org/2000/svg">
  <line x1="0" y1="10" x2="250" y2="10" style="stroke:red;stroke-width:12" />
</svg>
Try it Yourself »

Code explanation:

  • The <x1> and <y1> attributes define the start of the line (0,10)
  • The <x2> and <y2> attributes define the end of the line (250,10)

A Vertical Line

The following example creates a thick vertical line from position (0,0) to (0,200):

Sorry, your browser does not support inline SVG.

Here is the SVG code:

Example

<svg height="210" width="300" xmlns="http://www.w3.org/2000/svg">
  <line x1="0" y1="0" x2="0" y2="200" style="stroke:red;stroke-width:14" />
</svg>
Try it Yourself »

Code explanation:

  • The <x1> and <y1> attributes define the start of the line (0,0)
  • The <x2> and <y2> attributes define the end of the line (0,200)

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.