Tutorials References Exercises Menu
Paid Courses

HTML canvas beginPath() Method

❮ HTML Canvas Reference


Draw two paths on the canvas; one green and one purple:



var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

ctx.lineWidth = "5";
ctx.strokeStyle = "green"; // Green path
ctx.moveTo(0, 75);
ctx.lineTo(250, 75);
ctx.stroke(); // Draw it

ctx.strokeStyle = "purple"; // Purple path
ctx.moveTo(50, 0);
ctx.lineTo(150, 130);
ctx.stroke(); // Draw it
Try it Yourself »

Browser Support

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

beginPath() Yes 9.0 Yes Yes Yes

Definition and Usage

The beginPath() method begins a path, or resets the current path.

Tip: Use moveTo(), lineTo(), quadricCurveTo(), bezierCurveTo(), arcTo(), and arc(), to create paths.

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

JavaScript syntax: context.beginPath();

❮ HTML Canvas Reference