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

HTML canvas stroke() method

HTML canvas stroke() method

HTML canvas Reference HTML canvas Reference Manual

Example

Draw a path in the shape of a red letter L:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

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

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

ctx.beginPath();

ctx.moveTo(20,20);

ctx.lineTo(20,100);

ctx.lineTo(70,100);

ctx.strokeStyle="red";

ctx.stroke();

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


Definition and Usage

The stroke() method actually draws the path defined by the moveTo() and lineTo() methods. The default color is black.

**Tip:** Please use strokeStyle attribute to draw with another color/gradient.

JavaScript syntax: context.stroke(**);

HTML canvas Reference HTML canvas Reference Manual