Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const ctx = canvas.getContext("2d"); // Filled rectangle ctx.fillStyle = "#007bff"; ctx.fillRect(20, 20, 150, 80); // Outlined rectangle ctx.strokeStyle = "#dc3545"; ctx.lineWidth = 3; ctx.strokeRect(200, 20, 150, 80); // Clear a region ctx.clearRect(50, 40, 50, 40); // All take: x, y, width, height
Result
Open