JSFiddle - React, Tailwind, and code Playground

HTML

<canvas id="myCanvas" width="300" height="150">
</canvas>

JavaScript

// get canvas element.
var elem = document.getElementById('myCanvas');

// check if context exist
if (elem && elem.getContext) {

  // get context
  var context = elem.getContext('2d');
  if (context) {

    // x, y, width, height
    context.fillRect(0, 0, 50, 50);

    // x, y, width, height      
    context.fillRect(75, 0, 50, 50);
  }
}