Easy Tutorial
❮ Att Th Width Att Col Align ❯

HTML canvas fillRect() Method

HTML canvas Reference Manual

Example

Draw a 150*100 pixel filled rectangle:

JavaScript:


Browser Support

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the fillRect() method.

Note: Internet Explorer 8 and earlier versions do not support the <canvas> element.


Definition and Usage

The fillRect() method draws a "filled" rectangle. The default color of the fill is black.

Tip: Use the fillStyle property to set different colors, gradients, or patterns for the fill.

| JavaScript Syntax: | context.fillRect(x, y, width, height); | | --- | --- |

Parameter Values

Parameter Description
x The x coordinate of the upper-left corner of the rectangle.
y The y coordinate of the upper-left corner of the rectangle.
width The width of the rectangle, in pixels.
height The height of the rectangle, in pixels.
❮ Att Th Width Att Col Align ❯