Draw a rectangle onto the canvas examples




Draw a rectangle onto the canvas examples

<!DOCTYPE html>
<html>
   <head>
      <meta charset="UTF-8">
      <title>Drawing a Rectangle on Canvas</title>
      <style type="text/css">
         canvas {
            border: 1px 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.stroke();
         };
      </script>
   </head>
   <body>
      <canvas id="myCanvas" width="300" height="200"></canvas>
   </body>
</html>

Output