The max-height property sets the maximum vertical height of an element. It is especially useful when you want to restrict how tall a box can grow while still letting shorter content stay compact.
01
Height Cap
Set an upper limit.
02
none Default
No maximum by default.
03
Pixels / vh
Fixed and viewport caps.
04
Percentages
Relative to parent.
05
Overflow
Scroll when capped.
06
Related
height, min-height.
Fundamentals
Introduction
The max-height property in CSS defines the maximum height of an element. This property is useful for controlling how tall a box can grow in a block formatting context while keeping layouts predictable on different screen sizes.
By specifying a maximum height, you can prevent elements from growing beyond a certain point, which helps maintain layout and design consistency across different devices and screen sizes.
Definition and Usage
max-height always limits vertical size in normal horizontal layouts. The element can be shorter than the limit, but it will not grow taller once it reaches the maximum.
Pair max-height with overflow: auto when content might exceed the limit, and use it alongside height and min-height for full vertical sizing control.
💡
Beginner Tip
Think of max-height as a ceiling: the box can be shorter than the limit, but it cannot grow taller once it hits the maximum.
Foundation
📝 Syntax
Write max-height with a length, percentage, or none:
The initial value is none, meaning no maximum height constraint.
Length values such as px, rem, and vh set a fixed upper limit.
Percentages are relative to the containing block’s height.
Use with overflow when content may exceed the maximum and should scroll.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
none
Applies to
All elements
Inherited
No
Animatable
No
Common use
Scrollable panels, capped cards, responsive max heights in layouts
Defaults
🎯 Default Value
The default value of max-height is none. Without explicit styling, the element has no maximum height constraint and can grow as needed based on its content and other sizing properties.
Reference
💎 Property Values
These are the most common values you will use with max-height.
Value
Example
Meaning
none
max-height: none;
No maximum height constraint (default)
Length
max-height: 200px;
Defines a fixed maximum height using units such as px, rem, or vh
Percentage
max-height: 50%;
Maximum height relative to the containing block height
200px
Fixed pixel cap for panels and cards.
200px max
Pair with overflow for long content.
50%
Scales with the parent element height.
50% max
Parent needs a defined height.
none
No ceiling — content can grow freely.
No max
Default browser behavior.
Scope
Height, min-height, and max-height
Use physical height properties together when you want predictable vertical sizing in standard horizontal layouts.
height sets the preferred or fixed height of the box.
min-height sets the lower limit so content never shrinks below a minimum.
max-height sets the upper limit on the same vertical axis.
For writing-mode-aware layouts, see max-block-size on the logical block axis.
Compare
max-height vs max-block-size
Property
Axis
Best for
max-block-size
Block axis (depends on writing mode)
International layouts, reusable components, logical sizing systems
max-height
Always vertical
Simple pages with fixed max heights in horizontal writing
height
Always vertical
Preferred height paired with max/min limits
height
Always vertical
Simple fixed-height boxes in horizontal writing
Preview
👀 Live Preview
Three boxes with the same long text but different max-height caps:
none — grows with all content.
4rem max — Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
6rem max — Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
These values cap vertical height. Scrollbars appear when content exceeds the limit.
Hands-On
Examples Gallery
Try max-height with fixed caps, scrollable panels, viewport-relative limits, and side-by-side comparisons.
📚 Maximum Height Caps
Prevent panels and cards from growing too tall while still letting short content stay compact.
Example 1 — 200px Maximum with Scrolling
Set a 200px ceiling on height and add scrolling when content exceeds the limit.
max-height-200.html
<style>.box{max-height:200px;overflow:auto;background-color:lightgray;}</style><divclass="box">
Long paragraph content goes here…
</div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
How It Works
The box grows with its content until it hits 200px in height, then overflow: auto adds a scrollbar instead of letting text spill out.
Example 2 — Compact Scrollable Panel
Use a smaller cap for sidebar notes, comment threads, or any area that should stay short on the page.
Without a maximum, the box expands freely. With caps, the same content stops at the ceiling and scrolls inside the box.
🧠 How max-height Works
1
You declare a maximum height
Choose a length, percentage, or none to remove the cap entirely.
CSS rule
2
Content fills the box vertically
The element grows with its content up to the limit you set.
Box model
3
Growth stops at the ceiling
The box can stay shorter than max-height, but it cannot grow taller once it hits the maximum.
Constraint
=
Overflow behavior decides what happens next
Pair with overflow: auto so extra content scrolls inside the capped area.
Result
Compatibility
🖥 Browser Compatibility
The max-height property is universally supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. Older versions of Internet Explorer also support basic max-height values.
✓ Baseline · Universal support
Fundamental layout property
max-height has long been part of CSS layout and works consistently across browsers, much like height.
99%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
OperaAll modern versions
Full support
max-height property99% supported
Bottom line: You can rely on max-height in production layouts across all major browsers.
Wrap Up
Conclusion
The max-height property is a versatile tool for controlling the height of elements on your web page. By setting a maximum height, you can manage the layout of your content more effectively, especially in dynamic or responsive designs.
Use this property to ensure your web elements behave as expected and contribute to a better user experience. Pair it with overflow when content may exceed the cap.
Pair max-height with overflow: auto when content may exceed the cap
Use it alongside height and min-height for full vertical sizing control
Use viewport units like 50vh for responsive maximum heights
Test scroll behavior on touch devices when capping content areas
Prefer max-height for everyday layouts with broad browser support
❌ Don’t
Cap height without deciding what happens to overflow content
Confuse max-height with height — one sets a ceiling, the other sets preferred size
Expect max-height: 50% to work when the parent height is undefined
Skip overflow handling when content routinely exceeds the cap
Rely on max-height alone when layouts change writing mode (use max-block-size for logical sizing)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about max-height
Use these points when capping vertical size in layouts.
5
Core concepts
📏01
Maximum Cap
Sets the ceiling.
Purpose
📝02
none Default
No maximum limit.
Default
🔄03
Physical Axis
Always vertical.
Context
📈04
Overflow Pair
Scroll when capped.
UX
🛠05
Height Trio
height, min, max.
System
❓ Frequently Asked Questions
The max-height property sets the maximum vertical height of an element. The box can be shorter than the limit, but it cannot grow taller once it reaches the maximum.
The default value is none, which means there is no maximum height restriction and the element can grow with its content.
height sets a preferred or fixed size. max-height sets an upper limit only — the element can shrink below it when content is shorter.
Common values include none, length units like px, em, rem, and vh, and percentages relative to the containing block height.
Yes, when content may exceed the maximum height. Use overflow: auto or overflow-y: auto to add scrolling instead of clipping content unexpectedly.