/

HTML / CSS / JavaScript Tutorial

CSS Property: max-height

[this page | pdf | back links]

The CSS (CSS2) max-height property sets the maximum height an element can become. It overrides the height property.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

length

A CSS length

%

Defined as a percentage of that of the containing block

none

(default value). No limit

 

Default Value:

none

JavaScript syntax:

e.g. object.style.maxHeight="200px"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 100px; overflow: auto; background-color: yellow;}
p.x1 {max-height: 40px;}
</style>
</head>
<body>
<p>Element with default property</p>
<p class="x1">Property set using in-file HTML style</p>
<p id="x2">Property set using JavaScript</p>

<script>
document.getElementById("x2").style.maxHeight = "40px";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyMaxHeight() {
  var x = document.createElement("DIV"); x.style.maxHeight = "40px"; return (window.getComputedStyle(x, null).maxHeight == "40px");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile