Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas beginPath() Method

HTML canvas beginPath() Method

Canvas Object Reference Canvas object

Example

Draws two paths on the canvas; green and purple:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");

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

ctx.beginPath();

ctx.lineWidth="5";

ctx.strokeStyle="green"; // Green path

ctx.moveTo(0,75);

ctx.lineTo(250,75);

ctx.stroke(); // Draw it

ctx.beginPath();

ctx.strokeStyle="purple"; // Purple path

ctx.moveTo(50,0);

ctx.lineTo(150,130);

ctx.stroke(); // Draw it

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the beginPath() method.

**Note:** Internet Explorer 8 and earlier versions do not support .


Definition and Usage

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

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

**Tip:** Please use stroke() The method draws the exact path on the canvas.

JavaScript syntax: context.beginPath();

Canvas Object Reference Canvas object