X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Style height Property

Style Object Reference Style Object

Example

Set the height of a <button> element:

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

Try it yourself »


Definition and Usage

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

Internet Explorer Firefox Opera Google Chrome Safari

The height property is supported in all major browsers.


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


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook