Easy Tutorial
❮ Met Console Warn Event Ctrlkey ❯

HTML canvas lineTo() Method

Canvas Object

Example

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

JavaScript:


Browser Support

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

Note: Internet Explorer 8 and earlier versions do not support the <canvas> element.


Definition and Usage

The lineTo() method adds a new point and creates a line from that point to the last specified point in the canvas (this method does not actually draw the line).

Tip: Use the stroke() method to draw the path on the canvas.

| JavaScript Syntax: | context.lineTo(x, y); | | --- | --- |

Parameter Values

Parameter Description
x The x coordinate of the destination point of the path.
y The y coordinate of the destination point of the path.

More Examples

Example

Draw a path that forms the letter L:

JavaScript:


Canvas Object

❮ Met Console Warn Event Ctrlkey ❯