<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Filling Color inside a Rectangle on the Canvas</title> <style> canvas { border: 3px solid green; } </style> <script> window.onload = function() { var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.rect(60, 80, 200, 100); context.fillStyle = "purple"; context.fill(); context.lineWidth = 5; context.strokeStyle = "yellow"; context.stroke(); }; </script> </head> <body> <canvas id="myCanvas" width="350" height="250"></canvas> </body> </html>