HTML <canvas> height Attribute

The height attribute on a <canvas> tag sets the height of the canvas. The height is specified in pixels - without the ‘px‘ unit.

Example

#

A height attribute on a <canvas> element.

<canvas id="mycanvas" height="110" width="110"></canvas>

<script>

  ( () => {
    let canvas = document.getElementById("mycanvas");
    let context = canvas.getContext("2d");

    context.fillStyle = "lightblue";
    context.fillRect(5, 5, 100, 100);
  } )();

</script>

Using height

The height attribute specifies the height of the canvas.

The height is specified in pixels -- without the 'px' unit.

Percentages (%) are not allowed, but most browsers do support it.

The default height of a canvas is 150px.


Syntax

<canvas height="pixels" >

Values

#

Value Description
pixels Height of the canvas in pixels. The default is 150px.

Browser support

Here is when height support started for each browser:

Chrome
4.0 Jan 2010
Firefox
2.0 Oct 2006
IE/Edge
9.0 Mar 2011
Opera
9.0 Oct 2005
Safari
3.1 Mar 2008

You may also like

 Back to <canvas>
Guides