The height attribute on a <canvas> tag sets the height of the canvas.
The height is specified in pixels - without the ‘px‘ unit.
A <canvas> element with a height attribute.
<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>
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.
<canvas height="pixels" >
Value | Description |
---|---|
pixels | Height of the canvas in pixels. The default is 150px. |
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 |