How to draw a line with lineTo() in HTML5?

HTMLWeb DevelopmentFront End Technology

To draw a line in HTML, use the canvas element. With canvas, use the lineTo() method to draw a line. The lineTo() method includes x and y parameter values, which positions the line.


You can try to run the following code to draw a line with lineTo() in HTML5 −

<!DOCTYPE html>
      <title>HTML Canvas</title>
      <canvas id="newCanvas" width="300" height="150" style="border:1px solid #000000;"></canvas>
         var c = document.getElementById("newCanvas");
         var ctxt = c.getContext("2d");
         ctxt.moveTo(70, 50);
         ctxt.lineTo(50, 120);
Updated on 15-Jun-2020 11:55:14