Skip to content
Related Articles

Related Articles

HTML | canvas fill() Method
  • Last Updated : 30 Apr, 2019

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML canvas fillRect() 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>

chevron_right


Output:
fill_canvas

Example-2:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML canvas fillRect() 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>

chevron_right


Output:
canvas_fill

Supported Browsers:

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

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :