HTML height Attribute

HTML height Attribute: The HTML height attribute defines the height of the element. It specifies the height in pixels. The <canvas>, <embed> and <video> tag are not supported in HTML4. While for the <iframe> tag, the height should be defined in pixels or in % of the containing element.

HTML height Attribute

This attribute can be applied to <canvas>,<emebed>,<iframe>,<img>,<input>,<object>,<video> elements.

Syntax: <img height=”pixels”>



Browser Support

This attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Opera
  • Safari
  • Internet Explorer

Example: for using <canvas> element

<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#92B901";
ctx.fillRect(50, 50, 50, 50);
</script>
</body>
</html>

Output:

HTML canvas element

Example: for using <embed> element

<!DOCTYPE html>
<html>
<body>
<embed src="helloworld.swf" width="200" height="200" style="border:1px solid">
</body>
</html>

Output:

HTML height attribute embedded element1

HTML height attribute embedded element

 

Example: for using <iframe> element

<!DOCTYPE html>
<html>
<body>
<iframe src="logo.htm" width="200" height="200">
</iframe>
</body>
</html>

Example: for using <img> element

<!DOCTYPE html>
<html>
<body>
<img src="smiley.gif" alt="Smiley face" width="42" height="42">
</body>
</html>

Output:

HTML height attribute img element

 

Example: for using <input> element

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
</body>
</html>

Output:

HTML height attribute input element