HTML <canvas> heightAttribute

HTML canvas 标签参考手册HTML <canvas> Tag

Examples

A canvas (<canvas>) with a height and width of 200 pixels:

<canvas id="myCanvas" width="200" height="200" style="border:1px solid">

Try it Yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the height attribute.

Note:Internet Explorer 8 and earlier IE versions do not support the <canvas> tag.


Definition and Usage

The height attribute specifies the height of the <canvas> element, in pixels.

Tip:Whenever the height or width of the canvas is reset, the canvas content is cleared (see the example at the bottom of the page).

Tip:Please learn more about <canvas> in our HTML Canvastutorial.


Differences between HTML 4.01 and HTML 5

<canvas> is a new tag in HTML5.


Syntax

<canvas height="pixels">

Attribute Values

Value Description
pixels Specifies the height of the canvas in pixels (for example "100px" or just "100"). The default is "150".


实例

More Examples

Clear the canvas
How to clear the canvas by resetting the width or height attribute (using JavaScript).


HTML canvas 标签参考手册HTML <canvas> Tag

Other Extensions