Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas lineTo() method

HTML canvas lineTo() method

Canvas Object Reference Canvas object

Example

Begin a path and move to position 0,0. Create a line to position 300,150:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");

var ctx=c.getContext("2d");

ctx.beginPath();

ctx.moveTo(0,0);

ctx.lineTo(300,150);

ctx.stroke();

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome and Safari support the lineTo() method.

**Note:** Internet Explorer 8 and earlier versions do not support .


Definition and Usage

The lineTo() method adds a new point, then creates a line from that point to the last specified point in the canvas (this method does not itself create a line).

**Tip:** Please use stroke() The method draws the exact path on the canvas.

JavaScript syntax: context.lineTo(x,y);

Parameter value

Parameters Description
x The x-coordinate of the path's target position.
y The y-coordinate of the path's target position.

More examples

Example

Draw a path in the shape of the letter L:

YourbrowserdoesnotsupporttheHTMLcanvastag.

JavaScript:

var c=document.getElementById("myCanvas");

var ctx=c.getContext("2d");

ctx.beginPath();

ctx.moveTo(20,20);

ctx.lineTo(20,100);

ctx.lineTo(70,100);

ctx.stroke();

Try it »


Canvas Object Reference Canvas object