Style height Property

Example

Set the height of a <button> element:

document.getElementById("myBtn").style.height = "50px";
Try it Yourself »

Description

The height property sets or returns the height of an element.

The height property has effect only on block-level elements or on elements with absolute or fixed position. The overflowing content can be manipulated with the overflow property.

Tip: Use the width property to set or return the width of an element.


Browser Support

Property
height Yes Yes Yes Yes Yes

Syntax

Return the height property:

object.style.height

Set the height property:

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

Property Values

Value Description
auto The browser sets the height. This is default
length Defines the height in length units
% Defines the height in % of the parent element
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit


Technical Details

Default Value: auto
Return Value: A String, representing the height of an element
CSS Version CSS1

More Examples

Example

Change the height of a <div> element:

document.getElementById("myDIV").style.height = "500px";
Try it Yourself »

Example

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

document.getElementById("myImg").style.height = "300px";
document.getElementById("myImg").style.width = "300px";
Try it Yourself »

Example

Return the height of an <img> element:

alert(document.getElementById("myImg").style.height);
Try it Yourself »

Related Pages

CSS tutorial: CSS Dimension

CSS tutorial: CSS Box model

CSS reference: height property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.