You are here: >

HTML <canvas> tag

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.
</canvas>

Attributes

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

Compatibility

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

Also see: Animation, Browser, Compatibility