Sets or retrieves the maximum height for an element.
![]() |
Syntax
max-height:
<length>
|
<percentage>
Property values
A Variant that specifies or receives the maximum height for an element.
- length
-
Floating-point number followed by an absolute units designator (
cm,mm,in,pt, orpc) or a relative units designator (em,ex, orpx). For more information about the supported length units, see CSS Values and Units Reference. - percentage
-
Integer followed by a % that specifies a percentage of the containing block height to use as the maximum height of the element. If the height of the containing block is not explicitly set, then the element has no maximum height and the max-height property is interpreted as 0%. For more information on containing blocks and how their heights are computed, see the Cascading Style Sheets, Level 2.1 (CSS2.1) specification.
CSS information
| Applies To | All elements |
|---|---|
| Media | visual |
| Inherited | no |
| Initial Value |
Standards information
- CSS 2.1, Section 10.7
Remarks
max-height was introduced in Windows Internet Explorer 7.
The min-height/max-height attributes apply to floating and absolutely positioned block and inline-block elements, as well as some intrinsic controls. They do not apply to non-replaced inline elements, such as table columns and row/column groups. (A "replaced" element has intrinsic dimensions, such as an img or textArea.)
This property is enabled only under the strict !DOCTYPE.
Examples
The following example shows how the min-height and max-height attributes affect the layout of a div element. The example requires Internet Explorer 7 or later to view.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/minHeight7.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html>
<head>
<style>
.height {
float:left;
width:300px;
background:#fff;
margin:0 1em;
}
#example1 { min-height:200px; }
#example2 { max-height:100px; }
.content {
border:1px solid #c00;
padding:5px;
}
</style>
</head>
<body>
<div class="height" id="example1">
<div class="content">
<h2>{ min-height:200px }</h2>
<p>The height of this div is always at least 200px.<br/><br/>
The content does not fill the entire div.</p>
</div>
</div>
<div class="height" id="example2">
<div class="content">
<h2>{ max-height:100px }</h2>
<p>This div will not grow more than 100px in height.<br/><br/>
The content that does not fit in the div continues beyond it.</p>
</div>
</div>
</body>
</html>
See also
- CSSStyleDeclaration
- currentStyle
- runtimeStyle
- style
- Cascading Style Sheet Compatibility in Internet Explorer 7
Send comments about this topic to Microsoft
Build date: 11/29/2012
