HTML | DOM Style maxHeight Property

The maxHeight property set/return the maximum height of an element.
The maxHeight property affect only on block-level elements, absolute or fixed position elements.

Syntax:

  • It is used to set the maxHeight property:



    object.style.maxHeight = "none|length|%|initial|inherit"
    
  • It is used to return the maxHeight property:

    object.style.maxHeight
    

Example-1: Set the maximum height of element using length unit.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style maxHeight Property </title>
</head>
<style>
    #Geek1 {
        color: white;
        height: 100px;
        background: green;
    }
</style>
  
<body>
    <center>
        <h1 id="Geek1"
                GeeksForGeeks 
            </h1>
        <h2>DOM Style maxHeight Property </h2>
        <br>
        <button type="button" onclick="mygeeks()">
            Click to change
        </button>
        
        <script>
            function mygeeks() {
                
                // Set maximum height using 
                // Using length unit.
                document.getElementById(
                  "Geek1").style.maxHeight =
                  "40px";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output

  • Before click on the button:
  • After click on button:

Example-2: Set maximum height using “%”

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style maxHeight Property </title>
</head>
<style>
    #Geek1 {
        color: white;
        height: 50%;
        background: green;
    }
      
    #Geek_Center {
        background: yellow;
        width: 400px;
        height: 150px;
        margin-left: 150px;
        text-align: center;
    }
</style>
  
<body>
    <div id="Geek_Center">
        <h3 id="Geek1"
                GeeksForGeeks 
            </h3>
        <h2>DOM Style maxHeight Property </h2>
        <br>
        <button type="button" onclick="mygeeks()">
            Click to change
        </button>
    </div>
    <script>
        function mygeeks() {
            
            //set maximum height.
            document.getElementById(
              "Geek1").style.maxHeight = "35%";
        }
    </script>
</body>
  
</html>

chevron_right


Output

  • Before click on the button:
  • After click on button:

Supported Browsers: The browser supporte by HTML | DOM Style maxHeight Property>are listed below:

  • Google Chrome
  • Edge
  • Mozilla Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.