moveTo method

The moveTo method moves the drawing pen to the specified point without drawing anything. From this point, you can then start drawing with the lineTo method.

Syntax

javascriptcontext.moveTo(x, y);

Example

Let's draw a line:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.stroke();

Результат:

See also

  • the lineTo method
    that draws lines