Definition
The min-height CSS property is used to set the minimum height that an element can have. It ensures that the element’s height will not be smaller than the specified value.
The min-height property accepts various length units, such as pixels (px), percentages (%), viewport height (vh), or the auto keyword.
Here’s an example:
.container {
min-height: 200px;
}
In this example, the .container class sets a minimum height of 200px for the element. If the content inside the element requires more space, the height of the element will expand accordingly.
You can also use other length units or percentage values to set a relative minimum height:
.container {
min-height: 50%;
}
In this case, the .container class sets a minimum height of 50% of its containing element’s height. This allows the element to dynamically adjust its height based on the available space.
The min-height property is useful when you want to ensure that an element always has a minimum height, even when its content is sparse or absent. It helps maintain consistent proportions and prevents elements from becoming too small.
Syntax
.component {
min-height: 24rem;
}
Set min-height with absolute units, responsive percentages, or viewport-based lengths depending on the layout needs.
Values
-
<length>: fixed sizes usingpx,rem,em,vh,vw, and other length units. -
<percentage>: resolves against the size of the containing block (forwidth) or the available height when explicitly defined. -
auto: keeps the browser-calculated size without clamping the item. -
0: common reset to avoid overly large intrinsic minimum sizes (for examplemin-width: 0on flex items).
Practical Examples
.content {
width: min(90vw, 70ch);
max-width: 960px;
}
This pattern keeps copy readable on large screens while still shrinking gracefully on smaller devices.
With min-height
Auto height
<div class="grid gap-4 sm:grid-cols-2">
<div class="space-y-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">With min-height</p>
<div class="rounded-md border border-dashed border-slate-300 bg-slate-50 p-4 text-sm text-slate-700" style="min-height: 10rem;">
Consistent height keeps cards aligned even when copy is shorter.
</div>
</div>
<div class="space-y-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Auto height</p>
<div class="rounded-md border border-dashed border-slate-300 bg-slate-50 p-4 text-sm text-slate-700">
Without constraints, cards grow purely based on their content.
</div>
</div>
</div> Tips & Best Practices
- Use
min()/max()/clamp()to express responsive bounds without relying on many media queries. - Combine width constraints with
margin: 0 auto;to center fixed-width blocks. - Reset flex or grid children with
min-width: 0and/ormin-height: 0so overflow can shrink when necessary.
Accessibility & UX Notes
Ensure interactive controls remain at least 44px in their tap target size when you constrain dimensions. Strategic max widths also improve readability for long-form copy by keeping line lengths manageable.
Browser Support
Fully supported across modern desktop and mobile browsers. When supporting legacy IE, avoid logical properties such as inline-size unless you supply explicit fallbacks.
Related
-
min-width,max-width,min-height,max-heightfor complementary constraints. -
box-sizingto control whether padding and border are included in the computed size. - Logical properties (
inline-size,block-size) for writing-mode aware layouts.