HTML canvas fill() Method

❮ HTML canvas Reference

Example

let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");

ctx.beginPath();
ctx.rect(25, 25, 75, 50);
ctx.fillStyle = "red";
ctx.fill();

ctx.beginPath();
ctx.rect(50, 50, 75, 50);
ctx.fillStyle = "green";
ctx.fill();

Meaning

The fill() method fills the current drawing (path).


Standard Syntax

JavaScript syntax:

context.fill();



Browser Support




Status







❮ HTML canvas Reference