The max-height property sets the maximum vertical height of an element. It stops the used height from growing past the value you set.
The box can stay shorter than the limit. It cannot grow taller once it hits the ceiling. Pair it with overflow when content may exceed the cap. For writing-mode-aware sizing, see max-block-size.
Standard-track.
Not deprecated. Length, percentage, and none are Baseline. Intrinsic keywords (fit-content, max-content) are widely supported; stretch is newer and limited.
Limited support stretch
The stretch keyword for max-height is not ready for everyday use. Prefer lengths, percentages, or none.
Choose a ceiling, then decide what happens when content is taller than that ceiling.
Leave max-height: none when the box should grow freely.
Set a length or percentage to cap growth.
For percentages, give the parent an explicit height first.
Add overflow: auto (or overflow-y: auto) so extra content scrolls instead of spilling.
Piece
Required?
Role
Block or replaced element
Yes
Non-replaced inlines ignore max-height
max-height value
Yes
none, length, percentage, or keyword
Parent with set height
For %
Percentage resolves against the containing block
overflow
Recommended
Controls scroll or clip when content exceeds the cap
Try it
Live Preview
Same long text, different max-height values. Watch the box stop growing and scroll when capped.
The outer frame is 200px tall so 50% has a parent height to resolve against.
Box
Line one of sample content. Line two of sample content. Line three of sample content. Line four of sample content. Line five of sample content. Line six of sample content.
max-height: 80px
Code
CSS Examples
Each snippet focuses on max-height. Use Try It Yourself for a live editor.
Example 1 — Fixed Length Cap
Stop the box at 120px and scroll when content is taller.
CSS
<style>
div {
max-height: 120px;
overflow: auto;
}
</style>
<div>
Line one.<br>
Line two.<br>
Line three.<br>
Line four.<br>
Line five.<br>
Line six.
</div>
Line one of sample content. Line two of sample content. Line three of sample content. Line four of sample content. Line five of sample content. Line six of sample content.
How It Works
Set a ceiling.max-height: 120px stops vertical growth at 120 pixels.
Allow short content. If the text were only two lines, the box would stay shorter than 120px.
Handle overflow.overflow: auto adds a scrollbar when the six lines need more than 120px.
Other units work too. Try rem, em, or vh the same way.
Example 2 — Percentage of Parent
Cap a child at half of a parent that has an explicit height.
CSS
<style>
.parent {
height: 200px;
}
.child {
max-height: 50%;
overflow: auto;
}
</style>
<div class="parent">
<div class="child">
Line one.<br>
Line two.<br>
Line three.<br>
Line four.<br>
Line five.<br>
Line six.
</div>
</div>
Line one of sample content. Line two of sample content. Line three of sample content. Line four of sample content. Line five of sample content. Line six of sample content.
How It Works
Give the parent a height.200px makes the containing block explicit.
Use a percentage on the child.50% resolves to a 100px ceiling here.
Without a parent height. The percentage is treated as none, so the cap disappears.
Scroll the excess.overflow: auto keeps the layout tidy when text is taller than the cap.
Example 3 — No Cap vs Cap
Compare free growth with a hard ceiling on the same content.
CSS
<style>
.free {
max-height: none;
}
.capped {
max-height: 80px;
overflow: auto;
}
</style>
<div class="free">Grows with all lines.</div>
<div class="capped">
Line one.<br>
Line two.<br>
Line three.<br>
Line four.<br>
Line five.<br>
Line six.
</div>
none Line one of sample content. Line two of sample content. Line three of sample content. Line four of sample content. Line five of sample content. Line six of sample content.
80px Line one of sample content. Line two of sample content. Line three of sample content. Line four of sample content. Line five of sample content. Line six of sample content.
How It Works
Leave the default.none means no ceiling. The first box grows with every line.
Add a ceiling.80px stops the second box from growing past that height.
Scroll inside the cap. Extra lines stay reachable because of overflow: auto.
Remember the override rule. If height is larger than max-height, the max wins. If min-height is larger than the max, the min wins.
Edge Cases & Pitfalls
If the cap seems ignored, one of these is usually why.
percent
Percentage needs a parent height
If the containing block height depends on content (auto), a child max-height: 50% is treated as none.
overflow
Cap without overflow can clip
A max alone does not create a scrollbar. Set overflow so users can still reach hidden content.
override
max-height beats height
max-height overrides height when both apply. min-height overrides max-height if the min is larger.
inline
Non-replaced inlines ignore it
A plain span does not take max-height. Use a block, flex item, or replaced element.
a11y
Fixed caps can hide zoomed text
When users enlarge text, a tight max may clip content. Prefer flexible units and scrollable overflow for text-heavy boxes.
Compatibility
Browser Support
max-height is a browser layout property. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
max-height
Length, percentage, and none work everywhere. Intrinsic keywords are widely supported; stretch is newer and limited.
99%Common values
Google Chrome1+
Full
Mozilla Firefox1+
Full
Apple Safari1+
Full
Microsoft Edge12+
Full
OperaSupported
Full
Samsung InternetSupported
Full
Internet Explorer7+
Full
max-heightWidely supported
Bottom line: Safe for everyday ceilings. Treat stretch as progressive enhancement until support is broad.
Remember
Key Takeaways
Role: set a ceiling on how tall a box can grow.
Common values:none, lengths, and percentages.
Initial value:none. Not inherited.
Pair with overflow: scroll or clip when content exceeds the cap.
One line:max-height is a ceiling — the box can be shorter, never taller than the limit.
Frequently Asked Questions
It sets a maximum height for an element. The box can be shorter than the limit, but it cannot grow taller once it reaches that ceiling.
The initial value is none, which means there is no maximum height. The element can grow with its content.
height sets a preferred or fixed size. max-height only sets an upper limit. The box can still shrink below the max when content is short.
Yes. max-height overrides height when the preferred height is larger. min-height overrides max-height if they conflict.
A percentage max-height needs a containing block with an explicit height. If the parent height depends on content, the percentage is treated as none.
It is Baseline and widely available in all major browsers. Newer keywords like stretch have limited support. It is a browser layout property, not a Node.js feature.