HTML canvas fill() method
Example
Draw a 150*100 pixels rectangle, then fill it with red:
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 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