English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Complete List of HTML Tags

HTML canvas lineTo() method

lineTo() is a Canvas 2The D API uses a method to connect the end of a subpath to x, y coordinates with a straight line (this does not actually draw).

HTML canvas reference manual

Online Example

Start a path and move to position 0,0. Create a path that reaches 300,15A line: 0 of

Your browser does not support HTML5 canvas tag.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8>
<title>HTML canvas lineTo() method usage-Basic Tutorial(oldtoolbag.com)</title>/<title>
</<head>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3>
Your browser does not support HTML5 canvas tag.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(300,150);
ctx.stroke();
</script>
</body>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 9Firefox, Opera, Chrome, and Safari support 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 then creates a line from that point to the last specified point on the canvas (this method does not create a line).

Tip:Please use stroke() Method to draw an exact path on the canvas.

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

Parameter Value

 
ParameterDescription
xThe x-coordinate of the target position of the path.
yThe y-coordinate of the target position of the path.

Online Example

Draw a path with the shape of the letter L:

Your browser does not support the HTML canvas tag.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8>
<title>HTML canvas lineTo() method usage-Basic Tutorial(oldtoolbag.com)</title>/<title>
</<head>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3>
Your browser does not support HTML5 canvas tag.
</canvas>
<script>
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();
</script>
</body>
</html>
Test and see ‹/›
HTML canvas reference manual