YouTip LogoYouTip

Met Canvas Fill

# HTML canvas fill() Method [![Image 8: Canvas Object Reference Manual](#) Canvas Object](#) ## Example Draw a 150*100 pixel rectangle, then fill it with red color: YourbrowserdoesnotsupporttheHTML5canvastag. JavaScript: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.rect(20,20,150,100); ctx.fillStyle="red"; ctx.fill(); [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 fill() method. **Note:** Internet Explorer 8 and earlier versions do not support the element. * * * ## Definition and Usage The fill() method fills the current image (path). The default color is black. **Tip:** Use the (#) property to fill with another color/gradient. **Note:** If the path is not closed, the fill() method adds a line from the end of the path to the start to close it (just like [closePath()](#)), and then fills the path. | JavaScript Syntax: | _context_.fill(); | | --- | * * Canvas Object](#)
← Met Canvas StrokeMet Canvas Clearrect β†’