Advertisement
Home Open Editor ❯

HTML canvas fillRect() Method

Example

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

ctx.fillRect(25, 25, 75, 50);

Try this code ❯

Meaning

The fillRect() method draws a "filled" rectangle.


Standard Syntax

JavaScript syntax:

context.fillRect(x,y,width,height);


Advertisement

Parameter Values

Parameter Description
x Specifies the x-coordinate of the upper-left corner of the rectangle.
y Specifies the y-coordinate of the upper-left corner of the rectangle.
width Specifies the width of the rectangle, in pixels.
height Specifies the height of the rectangle, in pixels.
Home Open Editor ❯
Advertisement