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

maxHeight style property

Browser support:
7
Specifies or returns the maximum 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 maxHeight 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 greater than the value specified by the maxHeight property.
Note that this property works in Internet Explorer only from version 7.
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.maxHeight;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: max-height

Possible values:

The type of this property is string.
 One of the following values: 
height in non-negative length
The maximum height for the element in length units. For the supported length units, see the length page.
height in non-negative percentage
The maximum 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.
none
No limit on the height of the element.
Default: none.

Example HTML code 1:

This example illustrates the use of the max-height property:
<head>
    <style>
        .withMax {
            max-height: 50px;
            height: 100px;
            background: red;
        }

        .withouMax {
            height: 100px;
            background: red;
        }
    </style>
</head>
<body>
    <p class="withMax">
        Element has height: 100px and max-height: 50px. As a result, it should be 50 pixels high.
    </p>
    <p class="withouMax">
        Element has height: 100px. As a result, it should be 100 pixels high.
    </p>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the maxHeight property in JavaScript:
<head>
    <script type="text/javascript">
        function ChangeMaxHeight () {
            var pObj = document.getElementById ("myP");
            var input = document.getElementById ("myInput");

            pObj.style.maxHeight = input.value + "px";
        }
    </script>
</head>
<body>
    <p id="myP" style="height: 200px;background: #33CCFF;">Sample element with height: 200px</p>

    <input id="myInput" type="text" value="40" />
    <br />
    <button onclick="ChangeMaxHeight ();">Change the maxHeight 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