CSS max-height Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Sizing

What You’ll Learn

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.

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.

📝 Syntax

Write max-height with a length, percentage, or none:

syntax.css
element {
  max-height: length | percentage | none | initial | inherit;
}

Basic Example

max-height.css
.box {
  max-height: 200px;
  overflow: auto;
  background-color: lightgray;
}

Syntax Rules

  • 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.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toAll elements
InheritedNo
AnimatableNo
Common useScrollable panels, capped cards, responsive max heights in layouts

🎯 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.

💎 Property Values

These are the most common values you will use with max-height.

ValueExampleMeaning
nonemax-height: none;No maximum height constraint (default)
Lengthmax-height: 200px;Defines a fixed maximum height using units such as px, rem, or vh
Percentagemax-height: 50%;Maximum height relative to the containing block height
200px

Fixed pixel cap for panels and cards.

Pair with overflow for long content.

50%

Scales with the parent element height.

Parent needs a defined height.

none

No ceiling — content can grow freely.

Default browser behavior.

max-height vs max-block-size

PropertyAxisBest for
max-block-sizeBlock axis (depends on writing mode)International layouts, reusable components, logical sizing systems
max-heightAlways verticalSimple pages with fixed max heights in horizontal writing
heightAlways verticalPreferred height paired with max/min limits
heightAlways verticalSimple fixed-height boxes in horizontal writing

👀 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.

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>

<div class="box">
  Long paragraph content goes here…
</div>
Try It Yourself

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.

max-height-scroll.html
<style>
  .panel {
    max-height: 150px;
    overflow-y: auto;
    padding: 1rem;
    background: #dbeafe;
  }
</style>

<div class="panel">
  Scrollable panel content…
</div>
Try It Yourself

How It Works

A 150px maximum keeps the panel compact. Shorter content stays smaller; longer content scrolls inside the capped area.

📈 Responsive Maximums

Use viewport and comparison techniques so max caps adapt across screen sizes.

Example 3 — Viewport-Relative Cap (50vh)

Limit height relative to the viewport so tall content never dominates small screens.

max-height-vh.css
.hero-card {
  max-height: 50vh;
  overflow: auto;
  padding: 1.5rem;
}
Try It Yourself

How It Works

50vh means half the viewport height. The cap shrinks on short screens and grows on tall ones.

Example 4 — Compare No Max vs Two Caps

See how the same long text behaves with no limit, a tight cap, and a roomier cap.

max-height-compare.css
.none { max-height: none; }
.sm { max-height: 120px; overflow: auto; }
.md { max-height: 240px; overflow: auto; }
Try It Yourself

How It Works

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

🖥 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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Opera All modern versions
Full support
max-height property 99% supported

Bottom line: You can rely on max-height in production layouts across all major browsers.

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.

💡 Best Practices

✅ Do

  • 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)

Key Takeaways

Knowledge Unlocked

Five things to remember about max-height

Use these points when capping vertical size in layouts.

5
Core concepts
📝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.

Practice in the Live Editor

Open the HTML editor, set max-height, and preview capped scrollable content instantly.

HTML Editor →

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.

5 people found this page helpful