Code
Execute
<!DOCTYPE html> <html> <head> <title>wikitechy - HTML canvas fill() method </title> </head> <body> <h1>wikitechy-HTML canvas fill() method with example: </h1> <canvas id="wikitechyCanvas" width="500" height="250" style="border:1px solid #d3d3d3;" ></canvas> <script> var m = document.getElementById("wikitechyCanvas") ; var mas = m.getContext("2d") ; mas.beginPath(); mas.rect(30, 30, 200, 150); mas.fillStyle = "green" ; mas.fill(); mas.beginPath(); mas.rect(60, 60, 200, 150); mas.fillStyle = "red"; mas.fill(); </script> </body> </html>
Result