Met Canvas Clearrect
# HTML canvas clearRect() Method
[ Canvas Object](#)
## Example
Clear a rectangle within a given rectangle:
YourbrowserdoesnotsupporttheHTML5canvastag.
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(0,0,300,150);
ctx.clearRect(20,20,100,50);
[Try it Β»](#)
* * *
## Browser Support

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the clearRect() method.
**Note:** Internet Explorer 8 and earlier versions do not support the element.
* * *
## Definition and Usage
The clearRect() method clears the pixels in a specified rectangular area.
| JavaScript Syntax: | _context_.clearRect(_x,y,width,height_); |
| --- |
## Parameter Values
| Parameter | Description |
| --- | --- |
| _x_ | The x-coordinate of the upper-left corner of the rectangle to clear. |
| _y_ | The y-coordinate of the upper-left corner of the rectangle to clear. |
| _width_ | The width of the rectangle to clear, in pixels. |
| _height_ | The height of the rectangle to clear, in pixels. |
* * Canvas Object](#)
YouTip