Table of contents
- 1. Summary
- 2. Usage context
- 3. Attributes
- 4. DOM interface
- 5. Examples
- 6. Browser compatibility
- 6.1. Browser-specific notes
- 6.1.1. Firefox (Gecko)
- 6.1. Browser-specific notes
- 7. See also
Summary
The Canvas (<canvas>) HTML element can be used to draw graphics via scripting (usually JavaScript). For example, it can be used to draw graphs, make photo compositions or even perform animations.
For more articles on canvas, see the canvas topic page.
Usage context
| Permitted content | Transparent, either phrasing content or flow content. |
| Tag omission | None, both the start tag and end tag must be included |
| Permitted parent elements | Any element that accepts phrasing content or any element that accepts flow content. |
| Normative document | HTML 5, section 4.8.10 |
Attributes
Like all other HTML elements, this element has the global attributes.
-
width - The width of the coordinate space in CSS pixels. Defaults to 300.
-
height - The height of the coordinate space in CSS pixels. Defaults to 150.
Note: The displayed size of the canvas can be changed using a stylesheet. The image is scaled during rendering to fit the styled size.
DOM interface
Examples
<canvas id="canvas" width="300" height="300"> Sorry, your browser doesn't support the <canvas> element. </canvas>
Browser compatibility
| Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 1.5 (1.8) | 1.0 | 9.0 | 9.0 | 1.0 |
| Feature | Firefox Mobile (Gecko) | Android | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 1.0 (1.8) | ? | ? | ? | 1.0 |
Browser-specific notes
Firefox (Gecko)
- Before Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2) , the canvas width and height were signed integers instead of unsigned integers.
- Prior to Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3)
, a
<canvas>element with a zero width or height would be rendered as if it had default dimensions.

