Image height attribute

Definition and Usage

Height Attribute to set or return the image's Height attribute value.

Height attribute Specify the height of the image.

This attribute can also return the height of the image using CSS styles (see the example below).

Tip:Please use Width attribute Set or return the image's Width attribute value.

Example

Example 1

Change the height of the image to 300px:

document.getElementById("myImg").height = "300";

Try it yourself

Example 2

Return the height of the image:

var x = document.getElementById("myImg").height;

Try it yourself

Example 3

Change the height and width of the image to 300px and 450px respectively:

document.getElementById("myImg").height = "300";
document.getElementById("myImg").width = "450";

Try it yourself

Example 4

Return the height of the image using CSS styles:

var x = document.getElementById("myImg").height;

Try it yourself

Syntax

Return the height attribute:

imageObject.height

Set the height attribute:

imageObject.height = pixels

Attribute Value

Value Description
pixels Height in pixels (for example, height="100").

Technical Details

Return Value: Number, representing the height of the image in pixels.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <img> height Attribute