251 of 264 menu

fill method

The fill method fills a shape drawn via the lineTo, rect, arc methods and so on.

Syntax

context.fill();

Example

We draw a square and fill it with fill:

<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas> let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.moveTo(50, 50); ctx.lineTo(150, 50); ctx.lineTo(150, 150); ctx.lineTo(50, 150); ctx.fill();

:

See also

  • the fillStyle property
    that sets a fill color
  • the stroke method
    that creates a stroke
byenru