The lineTo() method is used to add a new point to create a line from that point to last specified point in the canvas,
Syntax:
context.lineTo(x, y);
Parameters:
- x: This parameter specifies the x-coordinate from where to create the line.
- y: This parameter specifies the y-coordinate from where to create the line.
Example 1:
<!DOCTYPE html> <html> <head> <title> HTML canvas lineTo() Method </title> </head> <body style="text-align:left;"> <h1>GeeksforGeeks</h1> <h2>HTML canvas lineTo() Method</h2> <canvas id="GFG" width="500" height="200"> </canvas> <script> var doc_id = document.getElementById("GFG"); var context = doc_id.getContext("2d"); context.beginPath(); context.moveTo(10, 10); context.strokeStyle = 'green'; context.lineTo(200, 100); context.stroke(); </script> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers: The browser supported by HTML canvas lineTo() Method are listed below:
- Google Chrome 4.0
- Internet Explorer 9.0
- Firefox 3.6
- Safari 4.0
- Opera 10.1
Recommended Posts:
- D3.js path.lineTo() Function
- HTML | canvas rect() Method
- HTML | canvas clearRect() Method
- HTML | canvas strokeRect() Method
- HTML | canvas fillRect() Method
- HTML | canvas fill() Method
- HTML | canvas stroke() Method
- HTML | canvas translate() Method
- HTML canvas rotate() Method
- HTML | canvas scale() Method
- HTML | canvas createLinearGradient() Method
- HTML | canvas beginPath() Method
- HTML | canvas quadraticCurveTo() Method
- HTML | canvas moveTo() Method
- HTML | canvas closePath() Method
- HTML | canvas isPointInPath() Method
- HTML | canvas arcTo() Method
- HTML | canvas strokeText() Method
- HTML | canvas arc() Method
- HTML | canvas fillText() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


