``` "> ``` " />
Easy Tutorial
❮ Av Prop Videotracks Tag Col ❯

HTML <img> height Attribute

HTML <img> Tag

Example

An image with both height and width set to 42 pixels:

<img src="smiley.gif" alt="Smiley face" 
    height="42" width="42">

Browser Support

All major browsers support the height attribute.


The height attribute specifies the height of the image, in pixels.

Tip: It is a good practice to specify both the height and width attributes for an image. If these attributes are set, space is reserved for the image on the page load. Without these attributes, the browser cannot know the size of the image, and thus cannot reserve appropriate space for it, leading to layout shifts when the image loads.

Tip: Do not scale the image using the height and width attributes. If you reduce the image size using these attributes, the user still has to download the large image (even if it appears small on the page). The correct approach is to resize the image to the appropriate dimensions using image editing software before using it on the web page.


Differences Between HTML 4.01 and HTML5

In HTML 4.01, the height could be defined in pixels or as a percentage of the containing element. In HTML5, the height value must be in pixels.


Syntax

Attribute Values

Value Description
pixels The height in pixels (e.g., height="100").
❮ Av Prop Videotracks Tag Col ❯