HTML canvas rect Method

❮ HTML canvas Reference

Example

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

ctx.beginPath();
ctx.rect(25, 25, 75, 50);
ctx.stroke();

Meaning

The rect() method creates a rectangle.


Standard Syntax

JavaScript syntax:

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



Browser Support




Status







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.
❮ HTML canvas Reference