Easy Tutorial
❮ Prop Password Readonly Prop Document Activeelement ❯

HTML canvas fill() Method

Canvas Object

Example

Draw a rectangle of 150*100 pixels and then fill it with red color:

JavaScript:


Browser Support

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

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


Definition and Usage

The fill() method fills the current image (path). The default color is black.

Tip: Use the fillStyle property to fill with a different color/gradient.

Note: If the path is not closed, the fill() method adds a line from the end point to the start point to close the path (just like closePath()) and then fills it.

| JavaScript Syntax: | context.fill(); | | --- | --- |


Canvas Object

❮ Prop Password Readonly Prop Document Activeelement ❯