Skip to content
Related Articles

Related Articles

Improve Article

HTML | canvas lineTo() Method

  • Last Updated : 10 Oct, 2019

The lineTo() method is used to add a new point to create a line from that point to last specified point in the canvas,


context.lineTo(x, y);


  • 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 canvas lineTo() Method
<body style="text-align:left;">
    <h2>HTML canvas lineTo() Method</h2>
    <canvas id="GFG" width="500" height="200">
        var doc_id = document.getElementById("GFG");
        var context = doc_id.getContext("2d");
        context.moveTo(10, 10);
        context.strokeStyle = 'green';
        context.lineTo(200, 100);


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

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :