Propiedad fillStyle

La propiedad fillStyle establece el color de relleno de una figura al dibujar en canvas. Su valor puede ser cualquier unidad CSS para colores.

Sintaxis

javascriptcontexto.fillStyle = color;

Ejemplo

Dibujemos un cuadrado usando rect y rellenémoslo con color rojo:

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();

Результат:

Ver también

  • método strokeStyle,
    que establece el color de la línea