Definition and Usage
The max-height CSS property is used to set the maximum height of a given element. It prevents the used value of the height property from becoming larger than the value specified for max-height.
max-height overrides height, but min-height overrides max-height.
- Initial none
- Applies to all elements but non-replaced inline elements, table columns, and column groups
- Inherited no
- Percentages The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the percentage value is treated as none.
- Media visual
- Computed Value the percentage as specified or the absolute length or none
- Animatable yes, as a length, percentage or calc(); when both values are lengths, they are interpolated as lengths; when both values are percentages, they are interpolated as percentages; otherwise, both values are converted into a calc() function that is the sum of a length and a percentage (each possibly zero), and these calc() functions have each half interpolated as real numbers.
- Canonical order the unique non-ambiguous order defined by the formal grammar
Syntax
Formal syntax: <length> | <percentage> | none | max-content | min-content | fit-content | fill-available
max-height: 3.5em max-height: 75% max-height: none max-height: max-content max-height: min-content max-height: fit-content max-height: fill-available max-height: inherit
Values
- <length>
- A fixed maximum height. See <length> for possible units.
- <percentage>
- The <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
- The intrinsic preferred height.
- min-content
- The intrinsic minimum height.
- fill-available
- The containing block height minus horizontal margin, border and padding. Some browsers implement an ancient name for this keyword, available.
- fit-content
- The same as max-content.
Examples
table { max-height: 75%; } form { max-height: none; }
Compatibility
Desktop browsers
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 7.0 | 7.0 | 1.0 |
applies to <table> | Not supported | (Yes) | Not supported | (Yes) | Not supported |
max-content , min-content , fit-content , and fill- available | Not supported | 3.0 (1.9)-moz | Not supported | Not supported | Not supported |
Mobile browsers
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | NA | NA | NA | NA | NA |