HTML <canvas> tag

Updated: 11/13/2018 by Computer Hope
HTML canvas tag

When writing in HTML, the <canvas> tag is a block element used to draw graphics using a scripting language like JavaScript. It is useful when you want to create graphs or perform simple animations on the fly. The following sections contain information about this tag, including an example of its code, and related attributes and browser compatibility.

Example of <canvas> code

<canvas id="firstCanvas" width="250" height="250">
Unfortunately, your browser doesn't support the canvas element.


Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. The following table shows all of the current unique HTML attributes for the <canvas> tag, and a description of each.

Attribute Description
height Designates the height of the canvas.
width Designates the width of the canvas.


Edge Internet Explorer Firefox Safari Opera Chrome
9.0+ 9.0+ 2.0+ 3.1+ 9.0+ 4.0+

Animation, Browser, Compatibility, Container tag, Web design terms