The canvas fill() Method is used to fill the current drawing path. The default color of the canvas fill() method is black.
Syntax:
context.fill()
Example-1:
<!DOCTYPE html> <html> <head> <title> HTML canvas fillRect() Method </title> </head> <body> <canvas id="GFG" width="500" height="300"> </canvas> <script> var x = document.getElementById("GFG"); var contex = x.getContext("2d"); contex.rect(50, 50, 350, 200); contex.fill(); contex.stroke(); </script> </body> </html> |
chevron_right
filter_none
Output:

Example-2:
<!DOCTYPE html> <html> <head> <title> HTML canvas fillRect() Method </title> </head> <body> <canvas id="GFG" width="500" height="300"> </canvas> <script> var x = document.getElementById("GFG"); var contex = x.getContext("2d"); contex.rect(50, 50, 350, 200); contex.fillStyle = "green"; contex.fill(); contex.stroke(); </script> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | canvas rect() Method
- HTML | canvas clearRect() Method
- HTML | canvas strokeRect() Method
- HTML | canvas fillRect() Method
- HTML | canvas stroke() Method
- HTML | canvas translate() Method
- HTML canvas rotate() Method
- HTML | canvas scale() Method
- HTML | canvas createLinearGradient() Method
- HTML | canvas beginPath() Method
- HTML | canvas quadraticCurveTo() Method
- HTML | canvas moveTo() Method
- HTML | canvas closePath() Method
- HTML | canvas isPointInPath() Method
- HTML | canvas arcTo() Method
- HTML | canvas strokeText() Method
- HTML | canvas arc() Method
- HTML | canvas fillText() Method
- HTML | canvas lineTo() Method
- HTML | canvas measureText() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


