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

HTML Reference Manual

HTML tag大全

HTML canvas moveTo() method

moveTo() is a Canvas 2The D API method that moves the starting point of a new subpath to the (x, y) coordinates.

HTML canvas Reference Manual

Online Example

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

Your browser does not support HTML5 canvas tag.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML canvas moveTo() method usage-Basic Tutorial(oldtoolbag.com)</<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 See «/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 9Firefox, Opera, Chrome, and Safari support moveTo(). Method.

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

Definition and Usage

The moveTo() method moves the path to a specified point on the canvas without creating a line.

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

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

Parameter Value

ParameterDescription
xThe x-coordinate of the target location of the path.
yThe y-coordinate of the target location of the path.
HTML canvas Reference Manual