var c = document.querySelector("canvas"); var ctx = c.getContext("2d"); // hex ctx.fillStyle = '#409EFF'; ctx.fillRect(0,0,100,100); // rgb || rgba ctx.fillStyle = 'rgba(103, 194, 58, 0.9)'; ctx.fillRect(110,0,100,100);
<canvas></canvas>