Tutorials References Exercises Bootcamps Videos Menu
Sign Up Create Website Get Certified Upgrade

HTML canvas moveTo() Method

❮ HTML Canvas Reference


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



let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.moveTo(0, 0);
ctx.lineTo(300, 150);
Try it Yourself »

Browser Support

The numbers in the table specify the first browser version that fully supports the method.

moveTo() Yes 9.0 Yes Yes Yes

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