how to change canvas background color javascript code example
Example 1: how to change canvas color in javascript
let canvas = document.getElementById("canvas");
let ctx = canvas.getContext("2d");
ctx.fillStyle = "#ff0000";
ctx.fillRect(20, 20, 150, 100);
Example 2: canvas set background color
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "blue";
ctx.fillRect(0, 0, canvas.width, canvas.height);