Canvas beginPath() Method

Definition and Usage

beginPath() Method starts a new path or resets the current path.

Tip:Please use these methods to create paths: moveTo(), lineTo(), quadricCurveTo(), bezierCurveTo(), arcTo() and arc().

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

Example

Draw two paths on the canvas; red and blue:

Your browser does not support the HTML5 canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineWidth="5";
ctx.strokeStyle="red"; // Red path
ctx.moveTo(0,75);
ctx.lineTo(250,75);
ctx.stroke(); // Draw the path
ctx.beginPath();
ctx.strokeStyle="blue"; // Blue path
ctx.moveTo(50,0);
ctx.lineTo(150,130);
ctx.stroke(); // Draw the path

Try It Yourself

Syntax

context.beginPath();

Browser Support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

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