Browse By Name
HTMLCSSJavaScriptAppendix
You are here: Reference > JavaScript > client-side > style handling > properties > minHeight

minHeight style property

A A Font size Print Content Add new content Share
Browser support:
Specifies or returns a minimum height for the visible area of an element.
This property has effect only on block-level elements or on elements with absolute or fixed position. The minHeight property contains only the pure height of the visible content, without the padding, scrollbar, border and the margin. The height of an element can never be less than the value specified by the minHeight property.
Note, this property works differently in Internet Explorer, depending on the document type declaration. For example, in case of the HTML 4.01 Transitional document type (<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">), it works for td elements but it does not work for div elements. In case of XHTML 1.1 document type (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">), it works for div elements but it does not work for td elements. See Example 1 and 2. For a detailed description of document types, see the page for the doctype element.
You can specify a range for the size of an element with the minWidth, minHeight, maxWidth and maxHeight properties. If you want to specify the exact size of an element, use the width and height properties.
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 or the getBoundingClientRect method.

Syntax:

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

Possible values:

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

Example HTML code 1:

This example illustrates the use of the min-height property:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
    <head>
        <style>
            .exampleHeight {
                height: 100px;
                overflow: auto;
                border: 3px solid red;
            }
            .exampleMinHeight {
                min-height: 100px;
                overflow: auto;
                border: 3px solid red;
            }
        </style>
    </head>
    <body>
        <div class="exampleHeight">
            The height style property of the element that contains this text is '100px'.
            <div style="height:150px; background-color:green;">The height of this green field is 150px.</div>
        </div>
        <br /><br />
        <div class="exampleMinHeight">
            The min-height style property of the element that contains this text is '100px'.
            <div style="height:150px; background-color:green;">The height of this green field is 150px.</div>
        </div>
        <br /><br />
        <div class="exampleMinHeight">
            The min-height style property of the element that contains this text is '100px'.
            <div style="height:30px; background-color:green;">The height of this green field is 30px.</div>
        </div>
    </body>
</html>
Did you find this example helpful? yes no

Example HTML code 2:

This example is equivalent to the previous one, but it uses the HTML 4.01 Transitional document type so it does not work in Internet Explorer:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <style>
            .exampleHeight {
                height: 100px;
                overflow: auto;
                border: 3px solid red;
            }
            .exampleMinHeight {
                min-height: 100px;
                overflow: auto;
                border: 3px solid red;
            }
        </style>
    </head>
    <body>
        <div class="exampleHeight">
            The height style property of the element that contains this text is '100px'.
            <div style="height:150px; background-color:green;">The height of this green field is 150px.</div>
        </div>
        <br /><br />
        <div class="exampleMinHeight">
            The min-height style property of the element that contains this text is '100px'.
            <div style="height:150px; background-color:green;">The height of this green field is 150px.</div>
        </div>
        <br /><br />
        <div class="exampleMinHeight">
            The min-height style property of the element that contains this text is '100px'.
            <div style="height:30px; background-color:green;">The height of this green field is 30px.</div>
        </div>
    </body>
</html>
Did you find this example helpful? yes no

Example HTML code 3:

This example illustrates the use of the minHeight property in JavaScript:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head>
    <script type="text/javascript">
        function ChangeMinHeight () {
            var division = document.getElementById ("myDiv");
            var input = document.getElementById ("myInput");

            division.style.minHeight = input.value + "px";
        }
    </script>
</head>
<body>
    <div id="myDiv" style="border: 3px solid red;">
        Use the button below to modify the min-height style property of the element that contains this text.
        <div style="height:50px; background-color:green;">The height of this green field is 50px.</div>
    </div>
    <br /><br />
    <input id="myInput" type="text" value="100" />
    <br />
    <button onclick="ChangeMinHeight ();">Change the minHeight of the element!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content