JavaScript
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(10, 10, 100, 100);Output
// Draws red rectangle on canvas
Canvas API enables 2D drawing.
Draw on canvas element
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(10, 10, 100, 100);// Draws red rectangle on canvas
Canvas API enables 2D drawing.