HTML <canvas> tag

Updated: 10/11/2017 by Computer Hope

HTML canvas tagWhen writing in HTML, the <canvas> tag is a block element used to draw graphics through the use of 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, as well as related attributes and browser compatibility.

Example 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, as well as a description of each.

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


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

Animation, Browser, Compatibility, Web design terms