Canvas API

Draw on canvas element

JavaScriptIntermediate
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.