HTML <img> heightAttribute

HTML img 标签参考手册HTML <img> Tag

Examples

An image with height and width of 42 pixels:

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

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the height attribute.


The height attribute specifies the height of an 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 these attributes, the browser cannot know the dimensions of the image and cannot reserve appropriate space for it, so the page layout will change when the image loads.

Tip:Do not use the height and width attributes to scale images. If you reduce an image using the height and width attributes, users will have to download a large image (even if it appears small on the page). The correct approach is to process the image to the appropriate size with software before using it on a 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

<img height="pixels">

Attribute Values

Value Description
pixels The height in pixels (e.g., height="100").


HTML img 标签参考手册HTML <img> Tag Other Extensions