THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML canvas moveTo() Method

HTML canvas Reference HTML Canvas Reference

Example

Begin a path, 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 yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the 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 the specified point in the canvas, without creating a line.

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

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

Parameter Values

Parameter Description Play it
x The x-coordinate of where to move the path to Play it »
y The y-coordinate of where to move the path to Play it »

HTML canvas Reference HTML Canvas Reference