Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to create a basic empty HTML canvas ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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;">


My Personal Notes arrow_drop_up
Last Updated : 12 Aug, 2021
Like Article
Save Article
Similar Reads
Related Tutorials