JSFiddle - React, Tailwind, and code Playground

by Richard Hunter

HTML

<div class="container">
  <h2>Hello world</h2>
  <canvas id="canvas" width="150" height="150"></canvas>
</div>

CSS

.container {
  position: relative;
}

#canvas {
  position: absolute;
  left: 0;
  top: 0;
}

h2 {
  position: relative;
  z-index: 1;
}

JavaScript

var canvas = document.getElementById('canvas');

if (canvas.getContext) {
  var ctx = canvas.getContext('2d');

  ctx.fillStyle = 'rgb(200, 0, 0)';
  ctx.fillRect(10, 10, 50, 50);

  ctx.fillStyle = 'rgba(0, 0, 200, 0.5)';
  ctx.fillRect(30, 30, 50, 50);
}