The fill() method in HTML canvas is used to fill the current drawing path. The default is black. The <canvas> element allows you to draw graphics on a web page using JavaScript. Every canvas has two elements that describes the height and width of the canvas i.e. height and width respectively.
Following is the syntax−
ctx.fill();
Let us now see an example to implement the fill() method of canvas −
Example
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="450" height="250" style="border:2px solid blue;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.beginPath(); ctx.rect(50, 60, 300, 200); ctx.fillStyle = "green"; ctx.fill(); </script> </body> </html>