Skip to content
Related Articles

Related Articles

Improve Article

How to create a basic empty HTML canvas ?

  • Last Updated : 12 Aug, 2021
Geek Week

HTML Canvas: The canvas is an element in HTML called <canvas> element, and it is used to draw graphics using JavaScript. It is only a container for graphics. You must use JavaScript to draw the graphics, and it has several methods for drawing paths, boxes, circles, text, and adding images.

A canvas is a rectangular area on an HTML page, and by default, a canvas has no border and no content.

Syntax:

<canvas>
    Content...
</canvas>

It is recommended to have an id attribute (to be referred to in a script), and a width and height attribute to define the size of the canvas. To add a border, use the style attribute.

 



Example: The following code demonstrates the empty canvas. 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <canvas id="myCanvas" width="300" height="300"
        style="border:1px solid #000000;">
        GfG
    </canvas>
</body>
  
</html>

Output:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :