Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML img height attribute

HTML height property

HTML img Tag Reference HTML tag

Example

An image with both height and width of 42 pixels:

Smiley face

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the height property.


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

**Tip:** It is a good practice to specify the height and width attributes for an image. If these attributes are set, space can be reserved for the image when the page loads. Without them, the browser cannot know the image's dimensions and cannot reserve appropriate space, so the page layout will change when the image loads.

**Tip:** Do not use the height and width attributes to scale images. If you shrink an image using these attributes, the user must download a large image (even if it looks small on the page). The correct approach is to process the image to an appropriate size with software before using it on the web page.


Differences between HTML 4.01 and HTML5

In HTML 4.01, the height should 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 (such as height="100").

HTML img Tag Reference HTML tag