YouTip LogoYouTip

Met Canvas Clearrect

# HTML canvas clearRect() Method [![Image 8: Canvas Object Reference](#) 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 ![Image 9: Internet Explorer](#)![Image 10: Firefox](#)![Image 11: Opera](#)![Image 12: Google Chrome](#)![Image 13: Safari](#) 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](#)
← Met Canvas FillMet Canvas Strokerect β†’