
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML canvas fill() Method
The fill() method in HTML canvas is used to fill the current drawing path. The default is black. The <canvas> element allows you to draw graphics on a web page using JavaScript. Every canvas has two elements that describes the height and width of the canvas i.e. height and width respectively.
Following is the syntax−
ctx.fill();
Let us now see an example to implement the fill() method of canvas −
Example
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="450" height="250" style="border:2px solid blue;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.beginPath(); ctx.rect(50, 60, 300, 200); ctx.fillStyle = "green"; ctx.fill(); </script> </body> </html>
Output
- Related Articles
- HTML canvas strokeRect() Method
- HTML canvas clearRect() Method
- HTML canvas fillRect() Method
- HTML canvas rect() Method
- HTML canvas stroke() Method
- How to completely fill web page with HTML canvas?
- HTML Canvas Basics
- HTML canvas Tag
- Make HTML5 Canvas fill the whole page
- HTML canvas fillStyle Property
- HTML canvas shadowColor Property
- HTML canvas shadowOffsetY Property
- HTML canvas shadowBlur Property
- HTML canvas strokeStyle Property
- HTML DOM Canvas Object\n

Advertisements