HTML height Attribute

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The HTML height attribute specifies the height of an element. It can be used on various elements, including but not limited to <img>, <iframe>, <embed>, <video>, and <canvas>, to directly define how tall the element should be displayed. The value of the height attribute can be specified in different units, such as pixels (px) or percentages (%), depending on the context and the specific element it's applied to. When used with images, for example, specifying the height helps the browser to allocate space on the page before the image is fully loaded, which can improve the layout stability during loading. It's important to note, however, that setting the height without considering the aspect ratio of content like images or videos might lead to distortion. Therefore, it is often recommended to use this attribute in conjunction with the width attribute to maintain the original aspect ratio of the content.

Syntax

<tagname height="pixels">

Values

  • pixelsA numeric height in pixels.

Applies To

The height attribute can be used on the following html elements.

Example

<img src="images/sunset.jpg" alt="Image description" height="100" width="200">

Browser Support

The following table will show you the current browser support for the HTML height Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 29th March 2024