CSS min-height Property
The CSS min-height property sets the minimum height an element is allowed to have.
It prevents an element from becoming shorter than a specified value while allowing it to grow when additional content requires more space. The property is commonly used for page sections, cards, responsive layouts, flexbox and grid items, and full-height page designs.
min-height Syntax
The min-height property accepts nonnegative lengths, percentages, intrinsic sizing keywords, and supported sizing functions.
Basic Syntax
selector {
min-height: 200px;
}
Relative Length
.panel {
min-height: 15rem;
}
Percentage Value
.panel {
min-height: 50%;
}
Viewport-Relative Height
.panel {
min-height: 60vh;
}
Intrinsic Sizing
.panel {
min-height: min-content;
}
.panel {
min-height: max-content;
}
.panel {
min-height: fit-content(300px);
}
Automatic Minimum
.panel {
min-height: auto;
}
CSS-Wide Keywords
.panel {
min-height: initial;
}
.panel {
min-height: inherit;
}
.panel {
min-height: unset;
}
.panel {
min-height: revert;
}
.panel {
min-height: revert-layer;
}
The initial value is auto. In ordinary block layout, this generally allows the element's height to be determined by its content. Flex and grid layouts can apply additional automatic minimum-size rules.
Property Values
| Value | Description |
|---|---|
auto |
Uses the automatic minimum height determined by the layout context. This is the initial value. |
<length> |
Sets a minimum height using units such as px, em, rem, or viewport units. |
<percentage> |
Sets the minimum height relative to the containing block's height when that size can be resolved. |
min-content |
Uses the intrinsic minimum-content height. |
max-content |
Uses the intrinsic maximum-content height. |
fit-content() |
Uses intrinsic sizing limits together with the supplied available-space value. |
stretch |
Uses the containing block's available height to establish a minimum for the element's margin box. Browser support varies. |
initial |
Resets the property to auto. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to auto because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | Elements that accept height constraints |
| Computed value | As specified, with relative lengths converted to absolute lengths |
| Animation type | By computed value type |
| Physical dimension | Height |
| Logical equivalent | min-block-size in horizontal writing modes |
How It Works
The min-height property establishes a lower limit on an element's height. If the preferred height is smaller than the minimum, the minimum takes precedence.
Height Below the Minimum
.box {
height: 100px;
min-height: 200px;
}
The minimum overrides the smaller preferred height, producing a used height of at least 200 pixels.
Height Above the Minimum
.box {
height: 300px;
min-height: 200px;
}
The preferred height remains 300 pixels because it satisfies the minimum.
Automatic Height
.box {
height: auto;
min-height: 200px;
}
The box is at least 200 pixels tall and can grow when its content requires additional space.
Automatic Minimum
.box {
min-height: auto;
}
The automatic minimum depends on the layout context. Ordinary block elements generally use a zero automatic minimum, while flex and grid items may have content-based automatic minimums.
Important Consideration
A minimum height does not establish an upper limit. Use max-height when the element must also have a maximum height.
min-height vs. height
The height property sets an element's preferred height, while min-height establishes a minimum height.
Fixed Preferred Height
.box {
height: 200px;
}
The box has a preferred height of 200 pixels. Content that exceeds this height can overflow depending on other sizing and overflow rules.
Minimum Height
.box {
min-height: 200px;
}
With automatic height, the box is at least 200 pixels tall but can expand to accommodate more content.
Minimum with Automatic Height
.box {
height: auto;
min-height: 200px;
}
This is useful for components that should maintain a minimum height without restricting their content.
Comparison
| Property | Purpose |
|---|---|
height |
Sets the preferred physical height. |
min-height |
Sets the minimum permitted physical height. |
max-height |
Sets the maximum permitted physical height. |
Length and Percentage Values
Length and percentage values allow minimum heights to be defined using fixed, relative, and container-dependent dimensions.
Pixels
.panel {
min-height: 250px;
}
The panel must be at least 250 pixels tall.
Root Font Units
.panel {
min-height: 15rem;
}
The minimum height is calculated relative to the root element's font size.
Font-Relative Units
.panel {
min-height: 12em;
}
The minimum height is based on the element's computed font size.
Viewport Height
.panel {
min-height: 60vh;
}
The minimum height is 60% of the viewport height.
Percentage Height
.parent {
height: 400px;
}
.child {
min-height: 50%;
}
When the containing block has a definite height of 400 pixels, the child's minimum height resolves to 200 pixels.
Calculated Minimum
.content {
min-height: calc(100vh - 120px);
}
The minimum is calculated from the viewport height minus 120 pixels. This can be useful when accounting for a header and footer.
Negative Values
.panel {
min-height: -100px;
}
Negative lengths and percentages are invalid. Zero and positive values are permitted.
Intrinsic Sizing Values
Intrinsic sizing values establish minimum heights based on the element's content and the available layout space.
min-content
.box {
min-height: min-content;
}
The minimum is based on the intrinsic minimum-content height.
max-content
.box {
min-height: max-content;
}
The minimum is based on the intrinsic maximum-content height.
fit-content()
.box {
min-height: fit-content(300px);
}
The fit-content() function uses intrinsic sizing limits while considering the supplied available-space value.
stretch
.box {
min-height: stretch;
}
The stretch keyword establishes a minimum based on the containing block's available height, accounting for the element's margin box. Browser support varies.
Important Consideration
Intrinsic sizing behavior depends on the element's content and layout context. Check browser compatibility when using newer sizing keywords or functions.
Minimum and Maximum Height
The min-height and max-height properties establish lower and upper height constraints.
Height Range
.panel {
min-height: 150px;
max-height: 400px;
}
The panel's used height is constrained between 150 and 400 pixels, subject to applicable sizing rules.
Preferred Height Below the Minimum
.panel {
height: 100px;
min-height: 200px;
}
The minimum overrides the smaller preferred height.
Preferred Height Above the Minimum
.panel {
height: 300px;
min-height: 200px;
}
The preferred height remains 300 pixels.
Minimum Takes Precedence
.panel {
min-height: 400px;
max-height: 250px;
}
When the minimum exceeds the maximum, the minimum height takes precedence.
Box Sizing
.panel {
box-sizing: border-box;
min-height: 200px;
padding: 20px;
border: 2px solid #64748b;
}
With border-box, the specified minimum includes padding and borders. With content-box, the minimum applies to the content box.
Responsive Layouts
Minimum heights are useful for creating flexible page sections and components that maintain a consistent minimum size without restricting content growth.
Full-Viewport Section
.hero {
min-height: 100vh;
display: grid;
place-items: center;
}
The hero section is at least as tall as the viewport and can grow when its content requires additional space.
Consistent Card Height
.card {
min-height: 180px;
padding: 20px;
box-sizing: border-box;
}
Cards with short content maintain a minimum height, while cards with longer content can grow.
Responsive Minimum Height
.content-panel {
min-height: clamp(150px, 30vh, 350px);
}
The minimum height responds to viewport height while remaining between 150 and 350 pixels.
Media Query Adjustment
.content-panel {
min-height: 300px;
}
@media (max-width: 767px) {
.content-panel {
min-height: 180px;
}
}
The minimum becomes smaller on narrow screens to reduce unnecessary empty space.
Page Layout
.page {
min-height: 100vh;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
The page fills at least the viewport height. The main content area expands to occupy remaining space when the page contains little content.
Important Consideration
A large minimum height can create excessive empty space on short screens. Test responsive designs with different viewport heights and enlarged text.
Viewport Height Units
Viewport-relative units are useful when an element should occupy a minimum portion of the visible screen.
Traditional Viewport Height
.hero {
min-height: 100vh;
}
The minimum is based on the viewport height. On mobile browsers, browser interface elements can affect how this unit relates to the currently visible area.
Small Viewport Height
.hero {
min-height: 100svh;
}
The svh unit uses the small viewport height, generally corresponding to the viewport when dynamic browser interface elements are expanded.
Large Viewport Height
.hero {
min-height: 100lvh;
}
The lvh unit uses the large viewport height, generally corresponding to the viewport when dynamic browser interface elements are retracted.
Dynamic Viewport Height
.hero {
min-height: 100dvh;
}
The dvh unit responds to changes in the dynamic viewport height as mobile browser interface elements appear or disappear.
Progressive Enhancement
.hero {
min-height: 100vh;
min-height: 100dvh;
}
Browsers that support dvh use the second declaration. Other browsers retain the traditional viewport-height value.
Important Consideration
Dynamic viewport units can change as browser interface elements move. Choose svh, lvh, or dvh according to the intended layout behavior.
Flexbox and Grid
Flex and grid items can have automatic minimum heights based on their content. This can affect how items shrink within constrained layouts.
Flex Item Minimum Height
.flex-container {
display: flex;
flex-direction: column;
height: 400px;
}
.flex-content {
flex: 1;
min-height: 0;
overflow-y: auto;
}
Setting min-height: 0 allows the flex item to shrink below its content-based automatic minimum. The overflow rule provides scrolling when needed.
Grid Item Minimum Height
.grid-container {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
height: 400px;
}
.grid-content {
min-height: 0;
overflow-y: auto;
}
The grid content area can shrink within the available height, while excess content remains accessible through scrolling.
Consistent Grid Cards
.card-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 16px;
}
.card {
min-height: 180px;
padding: 20px;
box-sizing: border-box;
}
Each card has a minimum height of 180 pixels. Grid alignment can also stretch items to match the height of their grid area.
Important Consideration
The automatic minimum height of a flex or grid item is not always zero. Use min-height: 0 when the layout requires the item to shrink below its content-based minimum, and manage overflow appropriately.
Logical Sizing
The min-height property always controls physical height. Logical sizing properties adapt to the writing mode of the element.
Physical Minimum Height
.box {
min-height: 200px;
}
This always constrains the vertical dimension.
Logical Minimum Block Size
.box {
min-block-size: 200px;
}
In horizontal writing modes, this corresponds to min-height. In vertical writing modes, it corresponds to min-width.
Logical Minimum Inline Size
.box {
min-inline-size: 200px;
}
In horizontal writing modes, this corresponds to min-width. In vertical writing modes, it corresponds to min-height.
Comparison
| Property | Horizontal Writing Mode | Vertical Writing Mode |
|---|---|---|
min-height |
Limits minimum height | Limits minimum height |
min-block-size |
Limits minimum height | Limits minimum width |
min-inline-size |
Limits minimum width | Limits minimum height |
Use physical sizing when the constraint must remain tied to height. Use logical sizing when it should follow the writing mode.
Overflow Behavior
A minimum height establishes a lower size limit but does not prevent content from exceeding the element's height.
Content Growth
.panel {
min-height: 200px;
height: auto;
}
The panel can grow beyond 200 pixels to accommodate additional content.
Fixed Height with Overflow
.panel {
height: 200px;
min-height: 150px;
overflow-y: auto;
}
The panel has a preferred height of 200 pixels. When its content is taller, vertical scrolling can make the excess content accessible.
Minimum and Maximum Constraints
.panel {
min-height: 150px;
max-height: 400px;
overflow-y: auto;
}
The panel can grow between its minimum and maximum heights. Content exceeding the maximum can scroll.
Important Consideration
Use automatic height when content should determine the element's final height. Add maximum-height constraints and scrolling only when the design requires a limited area.
min-height Example
This example compares a box with an automatic minimum height and a box with a minimum height of 140 pixels. Both contain a short paragraph.
HTML Example
<div class="min-height-demo">
<div class="min-height-item">
<h3>min-height: auto</h3>
<div class="min-height-box automatic">
<p>A short paragraph of content.</p>
</div>
</div>
<div class="min-height-item">
<h3>min-height: 140px</h3>
<div class="min-height-box limited">
<p>A short paragraph of content.</p>
</div>
</div>
</div>
CSS Example
.min-height-demo {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
}
.min-height-item {
min-width: 0;
}
.min-height-item h3 {
margin: 0 0 12px;
font-size: 1rem;
}
.min-height-box {
box-sizing: border-box;
padding: 15px;
background-color: #dbeafe;
border: 2px solid #2563eb;
border-radius: 6px;
}
.min-height-box p {
margin: 0;
}
.automatic {
min-height: auto;
}
.limited {
min-height: 140px;
}
@media (max-width: 575px) {
.min-height-demo {
grid-template-columns: 1fr;
}
}
min-height: auto
A short paragraph of content.
min-height: 140px
A short paragraph of content.
The first box uses the height required by its content. The second box remains at least 140 pixels tall, even when its content requires less space.
Full-Height Page Section
<section class="full-height-section">
<h2>Welcome</h2>
<p>This section fills at least the viewport height.</p>
</section>
.full-height-section {
min-height: 100vh;
display: grid;
place-content: center;
padding: 30px;
box-sizing: border-box;
background-color: #f0fdf4;
}
The section fills at least the viewport height and can grow when additional content is added.
Common Mistakes
Confusing min-height with height
.box {
min-height: 200px;
}
This establishes a minimum rather than a fixed height. With automatic height, the box can grow beyond 200 pixels.
Using Negative Values
.box {
min-height: -100px;
}
Negative lengths and percentages are invalid.
Conflicting Minimum and Maximum Heights
.box {
min-height: 400px;
max-height: 200px;
}
The minimum height takes precedence when it exceeds the maximum.
Expecting Percentages to Always Resolve
.box {
min-height: 50%;
}
A percentage minimum depends on the containing block's height. If that height is indefinite, the percentage may not produce the expected result.
Ignoring Automatic Minimum Sizes
Flex and grid items can resist shrinking because of content-based automatic minimum heights. Use min-height: 0 when the layout requires an item to shrink below that minimum.
Using a Large Minimum on Small Screens
.hero {
min-height: 800px;
}
A large fixed minimum can create unnecessary empty space on short screens. Consider viewport-relative units or responsive adjustments.
Forgetting Box Sizing
With content-box, padding and borders add to the specified minimum content-box height. Use border-box when the minimum should include them.
Assuming min-height Prevents Overflow
A minimum height does not restrict content growth or prevent overflow. Use appropriate maximum-height and overflow rules when needed.
Important Considerations
Keep the following points in mind when using min-height:
- The property sets a minimum physical height.
- Its initial value is
auto. - The property is not inherited.
- It does not prevent an element from growing beyond the minimum.
- Length and percentage values must be nonnegative.
- Percentage values depend on the containing block's height.
- Intrinsic sizing values depend on content and layout context.
min-heighttakes precedence when it exceedsmax-height.heightsets a preferred height, whilemin-heightestablishes a lower limit.box-sizingaffects whether padding and borders are included in the specified minimum.- Minimum heights are useful for cards, page sections, and full-height layouts.
- Viewport units can create minimum heights relative to the screen.
- Dynamic viewport units can improve sizing behavior on mobile browsers.
- Flex and grid items can have content-based automatic minimum heights.
- Setting
min-height: 0can allow certain flex and grid items to shrink. - The property always controls physical height, regardless of writing mode.
- Use
min-block-sizewhen the constraint should follow the logical block axis. - Test minimum heights with different viewport sizes and enlarged text.
Browser Support
The CSS min-height property is Baseline - Widely available. It is supported in current versions of all major browsers, including Chrome, Edge, Firefox, and Safari.
Basic length, percentage, and auto values have broad support. Newer intrinsic sizing values, such as stretch, may have different browser compatibility requirements.
For current compatibility information, visit Can I Use? and search for min-height.
When using newer viewport units or intrinsic sizing keywords, check compatibility for those specific features.
Specifications
The min-height property is defined in CSS Sizing Module Level 3.
CSS Sizing Module Level 3: Minimum Size Properties
The specification defines minimum size constraints and their relationship to preferred and maximum sizes.
For additional documentation and examples, consult MDN Web Docs.
