CSS max-height Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

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.

CSS Syntax

syntax.css
max-height: none | <length> | <percentage> | min-content | max-content | fit-content | initial | inherit;

Start with none, lengths, and percentages. Intrinsic keywords are optional extras.

Property Values

ValueDescriptionTry it
noneDefault. No maximum heightTry it
<length>Fixed ceiling such as 200px, 12rem, or 50vhTry it
<percentage>Percent of the containing block’s heightTry it
initialResets to noneTry it
inheritTakes the parent’s max-heightTry it

How to Use max-height

Choose a ceiling, then decide what happens when content is taller than that ceiling.

  1. Leave max-height: none when the box should grow freely.
  2. Set a length or percentage to cap growth.
  3. For percentages, give the parent an explicit height first.
  4. Add overflow: auto (or overflow-y: auto) so extra content scrolls instead of spilling.
PieceRequired?Role
Block or replaced elementYesNon-replaced inlines ignore max-height
max-height valueYesnone, length, percentage, or keyword
Parent with set heightFor %Percentage resolves against the containing block
overflowRecommendedControls scroll or clip when content exceeds the cap

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

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>
Try It Yourself

How It Works

  1. Set a ceiling. max-height: 120px stops vertical growth at 120 pixels.
  2. Allow short content. If the text were only two lines, the box would stay shorter than 120px.
  3. Handle overflow. overflow: auto adds a scrollbar when the six lines need more than 120px.
  4. 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>
Try It Yourself

How It Works

  1. Give the parent a height. 200px makes the containing block explicit.
  2. Use a percentage on the child. 50% resolves to a 100px ceiling here.
  3. Without a parent height. The percentage is treated as none, so the cap disappears.
  4. 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>
Try It Yourself

How It Works

  1. Leave the default. none means no ceiling. The first box grows with every line.
  2. Add a ceiling. 80px stops the second box from growing past that height.
  3. Scroll inside the cap. Extra lines stay reachable because of overflow: auto.
  4. 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.

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 Chrome 1+
Full
Mozilla Firefox 1+
Full
Apple Safari 1+
Full
Microsoft Edge 12+
Full
Opera Supported
Full
Samsung Internet Supported
Full
Internet Explorer 7+
Full
max-height Widely supported

Bottom line: Safe for everyday ceilings. Treat stretch as progressive enhancement until support is broad.

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.

Next: max-inline-size

Learn the logical maximum size on the inline axis.

max-inline-size tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful