{{CSSRef}}
Summary
The max-height
property is used to set the maximum height of an element. It prevents the used value of the {{ Cssxref("height") }} property from becoming larger than the value specified for max-height
.
{{ Cssxref("max-height") }} overrides {{cssxref("height")}}, but {{ Cssxref("min-height") }} overrides {{ Cssxref("max-height") }}.
{{cssinfo}}
Syntax
/* <length> value */ max-height: 3.5em; /* <percentage> value */ max-height: 75%; /* Keyword values */ max-height: none; max-height: max-content; max-height: min-content; max-height: fit-content; max-height: fill-available; /* Global values */ max-height: inherit; max-height: initial; max-height: unset;
Values
<length>
- A fixed maximum height. See {{cssxref("<length>")}} for possible units.
<percentage>
- The {{cssxref("<percentage>")}} is calculated with respect to the height of the containing block. If the height of the containing block is not specified explicitly, the percentage value is treated as
none
. none
- No limit on the height of the box.
max-content
{{experimental_inline()}}- The intrinsic preferred height.
min-content
{{experimental_inline()}}- The intrinsic minimum height.
fill-available
{{experimental_inline()}}- The containing block height minus vertical margin, border and padding. Some browsers implement an ancient name for this keyword,
available
. fit-content
{{experimental_inline()}}- The same as
max-content.
Formal syntax
{{csssyntax}}
Examples
table { max-height: 75%; } form { max-height: none; }
Specifications
Specification | Status | Comment |
---|---|---|
{{ SpecName('CSS3 Sizing', '#width-height-keywords', 'max-height') }} | {{ Spec2('CSS3 Sizing') }} | Adds the max-content , min-content , fit-content , and fill-available keywords.Both CSS3 Box and CSS3 Writing Modes drafts defined at some point these keywords. These drafts are superseded by this spec. |
{{ SpecName('CSS3 Transitions', '#animatable-css', 'max-height') }} | {{ Spec2('CSS3 Transitions') }} | Defines max-height as animatable. |
{{ SpecName('CSS2.1', 'visudet.html#min-max-heights', 'max-height') }} | {{ Spec2('CSS2.1') }} | Initial definition |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1.0")}} | 7.0 | 7.0 | 1.0 |
applies to <table> [1] |
{{ CompatNo() }} | {{CompatVersionUnknown()}} | {{ CompatNo() }} | {{CompatVersionUnknown()}} | {{ CompatNo() }} |
max-content , min-content , and fit-content {{ experimental_inline() }} |
{{ CompatNo() }} [3] | {{CompatGeckoDesktop("1.9")}}{{property_prefix("-moz")}} [2] | {{ CompatNo() }} | {{ CompatNo() }} | 9[3](bug) |
fill-available {{ experimental_inline() }} |
{{ CompatNo() }} | {{ CompatNo() }} {{ bug(527285) }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
applies to <table> [1] |
{{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
max-content , min-content , and fit-content {{ experimental_inline() }} |
{{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | 9[3](bug) |
fill-available {{ experimental_inline() }} |
{{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
[1] CSS 2.1 explicitely leaves the behavior of max-height
with {{ HTMLElement("table") }} undefined. Therefore any behavior is CSS2.1-compliant; newer CSS specifications may define this behavior, so Web developers shouldn't rely on a specific one now.
[2] Gecko experimentally implements the definitions given in CSS3 Basic Box. This one defines available
and not fill-available
. Also the definition of fit-content
is simpler than in CSS3 Sizing.
[3] WebKit implements an earlier proposal for setting the height to an intrinsic height: the keywords intrinsic
, instead of max-content
, and min-intrinsic
, instead of min-content
. There is no equivalent for fill-available
or fit-content
.
See also
- The box model
- {{ Cssxref("max-width") }}, {{ Cssxref("box-sizing") }}, {{ Cssxref("height") }}, {{ Cssxref("min-height") }}