# clearRect method

The `clearRect` method works like an eraser, clearing the rectangular area, making the content completely transparent.

## Syntax

`context.clearRect(x, y, width, height);`

## Example

Let's draw a square with `fillRect` and erase part of it with `clearRect`:

`<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>` `let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.fillRect(50, 50, 100, 100); ctx.clearRect(75, 75, 50, 50);`

:

## See also

- the `fillRect` method
  that draws a filled rectangle

← →
↑
en ru