height style property

Browser support:
Specifies or returns the height of the visible area for an element.
This property has effect only on block-level elements or on elements with absolute or fixed position. The overflowing content can be manipulated by the overflow property.
The height property contains the height of the visible content with the horizontal scrollbar, but without the padding, border and the margin.
The type of the height property is string. You can set or retrieve the value of the height property as an integer with the pixelHeight property. It contains the value in pixels. If you want to get or set the height property as a floating-point number that specifies the value in the current unit type of the height property, use the posHeight property.
The properties mentioned above can be used to access style settings. If you need the height of a rendered element you can use the clientHeight, offsetHeight and scrollHeight properties and the getBoundingClientRect method.

Syntax:

object.height;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: height

Possible values:

The type of this property is string.
 One of the following values: 
auto
Default. The height depends on the values of other properties.
height in non-negative length
The height of the element in length units. For the supported length units, see the length page.
height in non-negative percentage
The height of the element is the specified percentage of the height of parent element.
inherit
Takes the value of this property from the computed style of the parent element.
Default: auto.

Example HTML code 1:

This example illustrates the use of the height property:
<head>
    <style>
        .example {
            background-color: #E9E9E9;
            width: 300px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div class="example">The height is 200px</div>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the height property in JavaScript:
<head>
    <style>
        .example {
            background-color: #E9E9E9;
            width: 300px;
            height: 200px;
        }
    </style>

    <script type="text/javascript">
        function ChangeHeight () {
            var div = document.getElementById ("myDiv");
            var input = document.getElementById ("myInput");

            div.style.height = input.value;
        }
    </script>
</head>
<body>
    <div class="example" id="myDiv"></div>
    <input id="myInput" type="text" value="100" />
    <button onclick="ChangeHeight ();">Change the height of the div!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content