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.



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. 


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


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 :