Style height property

Definition and Usage

height Sets or returns the height of an element.

height This property is only effective for block-level elements or elements with absolute or fixed positions. Overflow content can be overflow property to operate.

Tip:Use width property Sets or returns the width of an element.

See also:

CSS Tutorial:CSS Dimension

CSS Tutorial:CSS Box Model

CSS Reference Manual:height property

Example

Example 1

Set the height of the <button> element:

document.getElementById("myBtn").style.height = "50px";

Try It Yourself

Example 2

Change the height of the <div> element:

document.getElementById("myDIV").style.height = "500px";

Try It Yourself

Example 3

Change the height and width of the <img> element:

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

Try It Yourself

Example 4

Return the height of the <img> element:

alert(document.getElementById("myImg").style.height);

Try It Yourself

Syntax

Return height property:

object.style.height

Set height property:

object.style.height = "auto|length|%|initial|inherit"

Property Value

Value Description
auto Browser sets the height. Default.
length Define the height with a length unit.
% Defined by the percentage of the parent element.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical Details

Default value: auto
Return value: A string representing the height of an element.
CSS Version: CSS1

Browser Support

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