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

HTML canvas fill() method

HTML canvas fill() method

Canvas Object Reference Canvas object

Example

Draw a 150*100 pixels rectangle, then fill it with red:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

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

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

ctx.rect(20,20,150,100);

ctx.fillStyle="red";

ctx.fill();

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


Definition and Usage

The fill() method fills the current image (path). The default color is black.

**Tip:** Please use fillStyle attribute to fill with another color/gradient.

**Note:** If the path is not closed, the fill() method adds a line from the end point of the path to the starting point to close the path (just like closePath() ), and then fills the path.

JavaScript syntax: context.fill(**);

Canvas Object Reference Canvas object