Fill color inside a rectangle shape on canvas examples




Fill color inside a rectangle shape on canvas examples

<!DOCTYPE html>
<html>
   <head>
      <title>Example of Fill Color inside a Rectangle</title>
      <style type="text/css">
         canvas {
            border: 2px solid red;
         }
      </style>
      <script type="text/javascript">
         window.onload = function(){
            var canvas = document.getElementById("myCanvas");
            var context = canvas.getContext("2d");
            context.rect(50, 50, 200, 100); 
            context.fillStyle = "#FB8B89";
            context.fill();
            context.lineWidth = 5;
            context.strokeStyle = "black";
            context.stroke();
         };
      </script>
   </head>
   <body>
      <canvas id="myCanvas" width="300" height="200"></canvas>
   </body>
</html>

Output