offline version v3


254 of 264 menu

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

context.fillStyle = color;

Example

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

<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas> let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.rect(50, 50, 100, 100); ctx.fillStyle = 'red'; ctx.fill();

:

See also

enru