Skip to content
Related Articles

Related Articles

Improve Article

HTML | canvas fill() Method

  • Last Updated : 08 Mar, 2021

The canvas fill() Method is used to fill the current drawing path. The default color of the canvas fill() method is black.
Syntax: 
 

context.fill()

Example-1: 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML canvas fill() Method
    </title>
</head>
 
<body>
    <canvas id="GFG"
            width="500"
            height="300">
  </canvas>
 
    <script>
        var x =
            document.getElementById("GFG");
        var contex =
            x.getContext("2d");
        contex.rect(50, 50, 350, 200);
        contex.fill();
        contex.stroke();
    </script>
 
</body>
 
</html>

Output: 
 

fill_canvas

Example-2: 
 



html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML canvas fill() Method
    </title>
</head>
 
<body>
    <canvas id="GFG"
            width="500"
            height="300">
  </canvas>
 
    <script>
        var x =
            document.getElementById("GFG");
        var contex =
            x.getContext("2d");
        contex.rect(50, 50, 350, 200);
        contex.fillStyle = "green";
        contex.fill();
        contex.stroke();
    </script>
 
</body>
 
</html>

Output: 
 

canvas_fill

Supported Browsers: 
 

  • Google Chrome
  • Internet Explorer 9.0
  • Firefox
  • Safari
  • Opera

 

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :