You are here: Reference > JavaScript > client-side > style handling > properties > minHeight

minHeight style property

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:
it does not work in case of the HTML 4.01 Transitional document type
it works in case of HTML5 and XHTML 1.1 document types in Internet Explorer from version 8, but does not work for td elements in Internet Explorer before version 8. 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>
<html>
    <head>
        <style>
            .minHeight {
                min-height: 100px;
                overflow: auto;
                border: 3px solid red;
            }
        </style>
    </head>
    <body>
        <table>
            <tr>
                <td class="minHeight">
                    The min-height style property of this <b>table cell</b> is '100px'.
                    <div style="height:30px; background-color:green;">The height of this green field is 30px.</div>
                </td>
            </tr>
        </table>
        <div class="minHeight">
            The min-height style property of this <b>division element</b> 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 the min-height property does not work for td elements in Internet Explorer before version 8:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <style>
            .minHeight {
                min-height: 100px;
                overflow: auto;
                border: 3px solid red;
            }
        </style>
    </head>
    <body>
        <table>
            <tr>
                <td class="minHeight">
                    The min-height style property of this <b>table cell</b> is '100px'.
                    <div style="height:30px; background-color:green;">The height of this green field is 30px.</div>
                </td>
            </tr>
        </table>
        <div class="minHeight">
            The min-height style property of this <b>division element</b> 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>
<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