The HTML height attribute specifies the height of an element.
Definition and Usage
➔ The height can be defined with or without the px suffix.
➔ It is recommended to use CSS to set the height in px or other units.
Syntax
//In HTML
<div>
<canvas id="mycanvas" height="120px" width="250px" style="border:2px solid #777;background-color:#d5e5f5;">
</canvas>
</div>
//In JavaScript
<script>
const element = document.getElementById('mycanvas');
element.height = 150;
</script>
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML height attribute example</title>
<meta charset="utf-8" />
</head>
<body>
<h3>HTML height attribute example</h3>
<p>height attribute specifies the height of an element</p>
<div>
<canvas id="mycanvas" height="120px" width="250px" style="border:2px solid #777;background-color:#d5e5f5;">
</canvas>
</div>
<script>
//const element = document.getElementById('mycanvas');
//element.height = 150;
</script>
</body>
</html>
Click on the "Try it Now" button to see how it works.