fillStyle property

The fillStyle property sets the fill color of a shape when drawn on the canvas. The value of the property is any CSS units for color.

Syntax

javascriptcontext.fillStyle = color;

Example

Let's draw a square with rect and fill it with red:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.rect(50, 50, 100, 100);
ctx.fillStyle = 'red';
ctx.fill();

Результат:

See also