How to fill paths in HTML Canvas

Overview

We can use the fill method to paint or fill the content area defined by path(s).

For example, we can use fill() to create paths and fill in the content area.

Example

const context = canvas.getContext("2d");
    context.beginPath()
     context.moveTo(0, 50)
     context.lineTo(50, 0)
     context.lineTo(100, 50)
     context.lineTo(0, 50)
     context.fill()
     context.closePath()

This will fill the content with the color black:

Note: Please refer to the following shots for information related to this topic:
-Drawing lines and paths
-Drawing triangles
-Drawing rectangles
-Drawing circles and arcs

Free Resources