HTML | canvas fill() Method
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:
html
<!DOCTYPE html> < html > < head > < title > HTML canvas fill() 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 > |
Output:
Example-2:
html
<!DOCTYPE html> < html > < head > < title > HTML canvas fill() 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 > |
Output:
Supported Browsers:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Safari
- Opera