clearRect method
Clears the pixels on a CanvasRenderingContext2D object within a given rectangle.
![]() ![]() |
Syntax
object.clearRect(x, y, w, h);
Parameters
x [in]
Type: numberThe x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.
y [in]
Type: numberThe x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.
w [in]
Type: numberThe width, in pixels, of the rectangle in relation to the coordinates of the canvas.
h [in]
Type: numberThe height, in pixels, of the rectangle in relation to the coordinates of the canvas.
Return value
This method does not return a value.
Standards information
- HTML Canvas 2D Context, Section 8
Remarks
The ICanvasRenderingContext2D::clearRect method clears the canvas to transparent black (that is, each pixel's RGBA value is equal to zero). To clear to a specific color, use the ICanvasRenderingContext2D::fillRect method.