Easy Tutorial
❮ Prop Input Time Type Prop Submit Value ❯

HTML canvas fillRect() Method

Canvas Object

Example

Draw a filled rectangle with dimensions 150*100 pixels:

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 the color, gradient, or pattern used for the fill.

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

Parameter Values

Parameter Description
x The x-coordinate of the top-left corner of the rectangle.
y The y-coordinate of the top-left corner of the rectangle.
width The width of the rectangle, in pixels.
height The height of the rectangle, in pixels.

Canvas Object

❮ Prop Input Time Type Prop Submit Value ❯