The Wayback Machine - https://web.archive.org/web/20240118180951/https://www.geeksforgeeks.org/html-canvas-lineto-method/
Open In App
Related Articles

HTML canvas lineTo() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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>


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
Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 09 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials