Tutorials Tailwind CSS Min/Max Width & Height
Ch 21 / 45
Chapter 21 Beginner 5 min read Tailwind CSS

Min/Max Width & Height in Tailwind CSS

Tailwind's min/max sizing utilities — min-w-*, max-w-*, min-h-*, max-h-* — give you constraint-based layout control without hard-coding fixed dimensions. Instead of locking an element to exactly w-64, you define its safe range: a minimum it can never shrink below and a maximum it can never exceed. This chapter covers every utility in all four groups, plus the three production layout patterns they unlock — the centred page container (max-w-5xl mx-auto), the sticky footer (min-h-dvh flex flex-col), and the scrollable panel (max-h-64 overflow-y-auto).

Advertisement
Google Ad Placeholder · 728×90 Leaderboard
What you'll learn
Set a minimum width floor: min-w-0, min-w-full, min-w-min, min-w-fit
Cap maximum width for containers: max-w-sm through max-w-screen-2xl and max-w-prose
Fix the classic flex overflow bug with min-w-0 on flex children
Use min-h-dvh flex flex-col for the sticky footer page layout pattern
Build scrollable panels: max-h-64 overflow-y-auto
Write arbitrary constraints: min-w-[200px], max-h-[calc(100vh-64px)]

Constraint Sizing — Ranges, Not Fixed Values

Fixed sizing (w-64, h-32) locks an element to one exact dimension regardless of context. Constraint sizing defines a safe range: the element is free to grow or shrink within that range, adapting to its content and viewport, but can never violate the boundaries you set. This is what makes responsive layouts work so naturally in Tailwind — you rarely need fixed sizes when you have the full min/max toolkit.

Fixed sizing vs constraint sizing — the fundamental difference Fixed sizing — exact value, no flexibility narrow viewport w-64 = 256px always ⚠ overflows narrow viewport wide viewport w-64 = 256px always doesn't use extra space Constraint sizing — adapts within a safe range narrow viewport max-w-5xl — fills available ✓ fills narrow viewport wide viewport capped at max-w-5xl ✓ centred, never too wide min-w-* floor — never narrower than this max-w-* ceiling — never wider than this min-h-* floor — never shorter than this max-h-* ceiling — never taller than this
min-w-* — Width Floor
Sets the minimum width the element can ever reach. Most important use: min-w-0 on flex children to let them shrink below their content size and prevent text overflow. Also used for minimum column widths in table layouts.
max-w-* — Width Ceiling
Sets the maximum width the element can reach. The single most-used constraint utility on any website — max-w-5xl mx-auto is the universal centred page container. Also sets reading widths (max-w-prose) and modal widths (max-w-lg).
min-h-* — Height Floor
Sets the minimum height an element can ever be. Page-level: min-h-dvh on a flex wrapper for the sticky footer pattern. Component-level: min-h-[120px] for textarea and card fields that should show at least a few lines.
max-h-* — Height Ceiling
Caps element height and — when paired with overflow-y-auto — creates a scrollable panel. Use for notification lists (max-h-64), dropdown menus (max-h-48), modals (max-h-screen), and any container with variable-length content.
Fixed vs constraint — quick rule Use fixed sizing (w-*, h-*) for elements whose size must never change: icons, avatars, fixed navbars, and UI chrome. Use constraint sizing (min-*, max-*) for anything that must adapt — page containers, prose widths, panels with variable content, and any element that needs to be both responsive and bounded.
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

min-w-* — Minimum Width Utilities

min-w-* sets the smallest width an element is allowed to be. By default, browsers give flex and grid items a minimum width equal to their content — this is what causes text to overflow its container. The fix — min-w-0 — removes that default and lets the item shrink below its content width so CSS overflow rules apply correctly.

min-w-0
min-width: 0px — Removes the browser's default minimum width. This is the standard fix for text or long URLs overflowing a flex child. Without it, flex items refuse to shrink below their content size. Add min-w-0 + overflow-hidden or truncate on the flex child to clip text correctly.
min-w-px
min-width: 1px — Guarantees at least a 1px hairline is always visible. Use for decorative separators and progress bars that must remain visible even at small values.
min-w-full
min-width: 100% — The element is always at least as wide as its parent. Use for table cells, input fields, and progress bars that must fill their container even when the content is very short.
min-w-min
min-width: min-content — The element is at least as wide as its minimum content width (its longest unbreakable word). Useful for table columns that must show at least the longest word without wrapping.
min-w-max
min-width: max-content — The element is always at least as wide as its full content on a single line. Prevents any text wrapping — useful for pill labels and badges that should never wrap to two lines.
min-w-fit
min-width: fit-content — At minimum shrink-wraps to content width while respecting the available space. Combines the best of both: won't overflow the container, but also won't be narrower than its content.
min-w-[N]
Arbitrary value — min-w-[200px], min-w-[8rem]. Any valid CSS min-width. Use for column widths in data tables where each column must be at least a certain width, or for side panels that must remain usable.
HTML — min-w-0 overflow fix and other min-width patterns
<!-- ❌ WITHOUT min-w-0: long text overflows flex container -->
<div class="flex gap-3 items-center">
  <img class="h-10 w-10 rounded-full flex-shrink-0" src="avatar.jpg" alt="">
  <div>
    <!-- This long name will overflow the flex container -->
    <p class="truncate">very-long-username-that-breaks-layout@example.com</p>
  </div>
</div>

<!-- ✅ WITH min-w-0: text truncates correctly -->
<div class="flex gap-3 items-center">
  <img class="h-10 w-10 rounded-full flex-shrink-0" src="avatar.jpg" alt="">
  <div class="min-w-0">
    <!-- min-w-0 allows truncate to work correctly -->
    <p class="truncate text-sm font-medium">very-long-username-that-breaks-layout@example.com</p>
  </div>
</div>

<!-- min-w-full: input always fills its label's container -->
<label class="block">
  <span class="text-sm font-medium text-gray-300">Email</span>
  <input type="email" class="min-w-full mt-1 px-4 py-2.5 border rounded-lg">
</label>

<!-- min-w-[N]: sidebar column never collapses below 240px -->
<aside class="min-w-[240px] max-w-xs p-4 bg-gray-900">
  Sidebar — always at least 240px
</aside>
The flex overflow bug — min-w-0 is the fix By spec, flex items have min-width: auto by default — they can never shrink below their content size. This means truncate (overflow: hidden; white-space: nowrap) won't work on a flex child with a long text string. The fix is always min-w-0 on the wrapper of the text: it overrides that default to 0px, allowing the flex item to shrink and letting overflow rules take effect.

max-w-* — Maximum Width Utilities

max-w-* is the most-used constraint utility in Tailwind. Every page container, every modal, every reading column uses it. The element can be as narrow as its content or viewport requires, but it can never exceed the cap you set — making layouts automatically responsive without a single breakpoint class.

max-w-* scale — all standard named sizes relative to a wide viewport full viewport (auto-margins centre each container) max-w-sm = 384px max-w-md = 448px max-w-lg = 512px max-w-2xl = 672px (prose reading) max-w-4xl = 896px max-w-5xl = 1024px ← universal page container ★★ max-w-7xl = 1280px (fills wide viewport)
max-w-sm
max-width: 24rem (384px) — Narrow forms, login cards, sign-up panels, and alert dialogs. Wide enough for a two-column form label + input, narrow enough to stay focused on mobile.
max-w-md
max-width: 28rem (448px) — Contact forms, confirmation dialogs, and profile cards. A comfortable form width that fits nicely centred on any tablet or desktop.
max-w-lg
max-width: 32rem (512px) — Standard modal dialog width. Wide enough for forms with multiple fields and their validation messages; pairs well with fixed inset-0 flex items-center justify-center for modal overlays.
max-w-2xl
max-width: 42rem (672px) — Optimal reading width for prose. Research shows ~65–75 characters per line is most comfortable to read. This is also what max-w-prose targets (65ch). Use for blog posts, articles, and documentation pages.
max-w-5xl
max-width: 64rem (1024px) — The most commonly used page container on the web. Comfortably fits two or three content columns on desktop while remaining readable on narrower screens. Pair with mx-auto px-4 for centring and gutters.
max-w-prose
max-width: 65ch — A special utility that sets the width to exactly 65 characters of the current font size. Unlike rem-based values, it adapts to the font size automatically — the line length stays ideal whether you use small or large body text.
max-w-full
max-width: 100% — Prevents overflow without enforcing a specific breakpoint. The essential class for responsive images: img class="max-w-full h-auto" ensures images never overflow their container at any screen width.
HTML — max-w patterns: container, prose, modal, image
<!-- ✅ Universal page container -->
<div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
  All page content — centred, capped at 1024px, guttered
</div>

<!-- Prose / article — optimal reading width -->
<article class="max-w-prose mx-auto px-4 py-10">
  <!-- max-w-prose = 65ch, adapts to font-size automatically -->
  Long-form blog content...
</article>

<!-- Login form — narrow focused width -->
<div class="min-h-dvh flex items-center justify-center px-4">
  <form class="w-full max-w-sm bg-gray-800 rounded-2xl p-8 space-y-4">
    <h2 class="text-xl font-bold text-white">Sign in</h2>
    <input type="email" class="w-full px-4 py-2.5 border border-gray-600 rounded-lg">
    <button class="w-full py-2.5 bg-cyan-500 text-white rounded-lg font-semibold">Sign in</button>
  </form>
</div>

<!-- Modal dialog -->
<div class="fixed inset-0 bg-black/50 flex items-center justify-center p-4">
  <div class="w-full max-w-lg max-h-[90vh] overflow-y-auto
           bg-gray-800 rounded-2xl shadow-2xl p-6">
    Modal content
  </div>
</div>

<!-- Responsive image — never overflows container -->
<img src="hero.jpg" alt="Hero" class="max-w-full h-auto rounded-xl">
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

min-h-* & max-h-* — Height Constraints

Height constraints work on the same principle as width constraints but along the vertical axis. min-h-* guarantees a minimum height — the element can grow taller but never shorter. max-h-* caps the height — the element can be shorter but never taller. Together they power the two most common height-related patterns: the sticky footer and the scrollable panel.

min-h-* grows beyond floor • max-h-* is hard-capped with overflow scroll min-h-dvh — sticky footer min-h-dvh flex flex-col header (fixed height) main (flex-1) grows to fill remaining height — pushes footer down footer (always at bottom) max-h-64 — scrollable panel max-h-64 overflow-y-auto Item 1 Item 2 Item 3 (cut — scroll to see) Items 4, 5, 6... exist below Panel stays at 256px, user scrolls
min-h-0
min-height: 0px — Removes minimum height. Critical for enabling overflow-y-auto on a flex child — flex items default to min-height: auto, which prevents them from shrinking to show a scrollbar. Add min-h-0 to the flex child to fix scrollable sidebars and panels inside flex layouts.
min-h-dvh
min-height: 100dvh — The mobile-safe page wrapper for sticky footers. The page is at least one full viewport height, can grow if content is taller, and the viewport height adapts to mobile browser chrome. Use as: <body class="min-h-dvh flex flex-col">.
min-h-screen
min-height: 100vh — At least the viewport height but uses the fixed vh unit. Works well on desktop; prefer min-h-dvh on mobile. Also useful for login/error pages that must fill the screen even with very little content.
max-h-32…96
Capped heights on the 4px scale — max-h-32 = 128px, max-h-48 = 192px, max-h-64 = 256px, max-h-96 = 384px. Always pair with overflow-y-auto to create a scrollable panel. The most used pattern: max-h-64 overflow-y-auto for notification dropdowns and comment lists.
max-h-screen
max-height: 100vh — Caps at viewport height. Use for modals and drawers that should not exceed the screen: max-h-[90vh] overflow-y-auto leaves a comfortable margin at the top and bottom while allowing internal scrolling.
max-h-dvh
max-height: 100dvh — Mobile-safe viewport cap for modals and drawers. Adapts as the browser chrome shows or hides. The modern replacement for max-h-screen on mobile: use max-h-dvh overflow-y-auto on modal inner content.
HTML — min-h and max-h patterns
<!-- Scrollable notification panel -->
<div class="max-h-64 overflow-y-auto rounded-xl border border-gray-700
           bg-gray-800 divide-y divide-gray-700">
  <div class="px-4 py-3 text-sm hover:bg-gray-700">You have a new message</div>
  <div class="px-4 py-3 text-sm hover:bg-gray-700">Your order was shipped</div>
  <!-- more items scroll inside the 256px panel -->
</div>

<!-- Scrollable modal (max-h-[90vh]) -->
<div class="fixed inset-0 bg-black/60 flex items-center justify-center p-4">
  <div class="w-full max-w-lg max-h-[90vh] overflow-y-auto
           bg-gray-800 rounded-2xl shadow-2xl">
    <div class="sticky top-0 bg-gray-800 p-6 border-b border-gray-700">
      <h2 class="text-lg font-semibold text-white">Dialog Title</h2>
    </div>
    <div class="p-6">Long scrollable content...</div>
  </div>
</div>

<!-- min-h-0 fix: scrollable sidebar inside flex layout -->
<div class="flex h-dvh">
  <!-- min-h-0 lets the sidebar shrink and show its own scrollbar -->
  <aside class="w-64 min-h-0 flex flex-col overflow-y-auto bg-gray-900 p-4">
    <nav>Very long navigation list...</nav>
  </aside>
  <main class="flex-1 min-h-0 overflow-y-auto p-8">
    Main scrollable content
  </main>
</div>

<!-- min-h for textarea — always shows 3 lines minimum -->
<textarea class="w-full min-h-[96px] px-4 py-3 border border-gray-600
             rounded-lg resize-y bg-gray-800 text-white"
           placeholder="Write your message..."></textarea>
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

Responsive Constraints — Stacking Breakpoint Prefixes

Every min/max utility accepts all five responsive prefixes (sm:, md:, lg:, xl:, 2xl:). This lets you progressively unlock more space as the screen grows — mobile gets full-width, tablet gets a constrained column, desktop gets the final capped container — all in one class string, zero media queries.

max-w-full
mobile (stacked)
fills 100% width
sm:max-w-xl
≥ 640px
capped at 576px
md:max-w-3xl
≥ 768px
capped at 768px
lg:max-w-5xl
≥ 1024px
capped at 1024px
xl:max-w-7xl
≥ 1280px
capped at 1280px
mx-auto
all sizes
always centred
HTML — responsive min/max constraints with breakpoint prefixes
<!-- Progressive container: grows as viewport grows -->
<div class="w-full max-w-full sm:max-w-xl md:max-w-3xl lg:max-w-5xl xl:max-w-7xl
           mx-auto px-4">
  <!-- Starts full-width on mobile, progressively constrains -->
</div>

<!-- Responsive max-h: taller panel on larger screens -->
<div class="max-h-48 sm:max-h-64 lg:max-h-96 overflow-y-auto
           border border-gray-700 rounded-xl bg-gray-800">
  <!-- 192px on mobile, 256px on sm, 384px on lg -->
  Scrollable list content...
</div>

<!-- min-w responsive: sidebar narrows on small screens -->
<aside class="min-w-[56px] sm:min-w-[180px] lg:min-w-[240px]
           max-w-xs transition-all duration-300">
  <!-- Icon-only on mobile, labels on sm+, full sidebar on lg+ -->
</aside>

<!-- Card that has a minimum width in grid layouts -->
<div class="grid gap-4" style="grid-template-columns: repeat(auto-fill, minmax(280px, 1fr))">
  <!-- auto-fill + minmax = cards that are always at least 280px -->
  <div class="min-w-0 p-6 bg-gray-800 rounded-2xl">Card</div>
</div>

<!-- Responsive min-h: panel taller on desktop -->
<section class="min-h-[300px] md:min-h-[500px] lg:min-h-dvh
             flex items-center justify-center bg-slate-900">
  Hero content — taller as viewport grows
</section>
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

Quick Reference — All Min/Max Utilities

Class CSS Property Notes
min-w-0 min-width: 0px Fix flex child overflow — most important ★★
min-w-px min-width: 1px Always at least 1px visible
min-w-full min-width: 100% At least fills parent width ★
min-w-min min-width: min-content At least the shortest word width
min-w-max min-width: max-content No text wrapping floor
min-w-fit min-width: fit-content Fit-content floor
min-w-[N] Custom Arbitrary: min-w-[200px] ★
max-w-sm max-width: 24rem 384px — forms, dialogs ★
max-w-md max-width: 28rem 448px — contact forms ★
max-w-lg max-width: 32rem 512px — modals ★
max-w-xl max-width: 36rem 576px
max-w-2xl max-width: 42rem 672px — prose ★
max-w-4xl max-width: 56rem 896px
max-w-5xl max-width: 64rem 1024px — page container ★★
max-w-7xl max-width: 80rem 1280px — dashboard ★
max-w-prose max-width: 65ch Optimal reading width ★
max-w-full max-width: 100% Prevent overflow — responsive images ★★
max-w-none max-width: none Remove max-width cap
max-w-[N] Custom Arbitrary: max-w-[760px] ★
min-h-0 min-height: 0px Enable scroll on flex child ★★
min-h-full min-height: 100% At least fills parent height
min-h-screen min-height: 100vh At least full viewport ★
min-h-dvh min-height: 100dvh Mobile-safe page wrapper ★★
min-h-svh min-height: 100svh Small viewport minimum
min-h-[N] Custom Arbitrary: min-h-[120px] ★
max-h-32…96 N × 0.25rem Fixed cap + overflow-y-auto ★★
max-h-full max-height: 100% Cap at parent height — images ★
max-h-screen max-height: 100vh Modal / drawer max ★
max-h-dvh max-height: 100dvh Mobile-safe modal cap ★
max-h-[N] Custom Arbitrary: max-h-[calc(100vh-64px)] ★

★ = commonly used • ★★ = used on virtually every project

Featured Course
Master Tailwind CSS — Sizing, Layout & Production UI
From sizing utilities to full dashboard layouts. Covers all Tailwind v4 utilities, responsive grid systems, dark mode, and 5 real-world projects with live mentoring.
45 Chapters 10+ Hours 5 Real Projects Certificate Live Mentoring
⇹
⭐ 4.9 · 1,200+ students
Tailwind CSS Min/Max Width & Height Cheat Sheet
Free one-page cheat sheet covering all min-w, max-w, min-h, max-h utilities — with the container, sticky footer, scrollable panel patterns and responsive constraint examples.
min-w-0 fix max-w-5xl container max-w-prose min-h-dvh max-h + overflow Responsive
Download Free Cheat Sheet
Chapter Summary
  • Constraint vs fixed sizing — w-*/h-* lock an element to one exact dimension. min-*/max-* define a safe range — the element adapts between the floor and ceiling, making layouts responsive by default without breakpoint classes.
  • min-w-0 — the flex overflow fix — Flex items default to min-width: auto which prevents them shrinking below content size. min-w-0 removes that default so truncate and overflow-hidden work correctly. Add it to the text wrapper, not the text element itself.
  • max-w-5xl mx-auto px-4 — the universal page container. Caps at 1024px, centres with auto margins, gutters with 16px padding on mobile. Used on every production website — memorise this pattern.
  • max-w-prose — sets max-width: 65ch, the optimal reading line length. Unlike rem-based values, it adapts to the element's current font size automatically. Use on article and blog content.
  • min-h-dvh flex flex-col — the sticky footer pattern. Page is at least one dynamic viewport height; flex-1 on <main> grows it to fill remaining space; footer always sits at the bottom even on short-content pages.
  • max-h-64 overflow-y-auto — the scrollable panel pattern. Element is capped at 256px; any content beyond that scrolls internally. Use for notification dropdowns, comment lists, log viewers, and any container with variable-length content.
  • min-h-0 on flex children — the scrollable flex child fix. By default flex children cannot shrink below their content height. min-h-0 removes that constraint and allows overflow-y-auto to work correctly inside flex layouts (scrollable sidebars, scrollable main panels).
  • Responsive constraints — all min/max utilities accept breakpoint prefixes. max-w-full sm:max-w-xl lg:max-w-5xl mx-auto progressively constrains a container as the viewport grows — full-width on mobile, capped on desktop — with no custom CSS needed.

Quick Check — Questions & Answers

Test your understanding. Click a question to reveal the answer.

w-64 sets width: 256px — the element is always exactly 256px wide, regardless of its parent or viewport. On a 320px mobile screen, a w-64 element will still be 256px wide and may leave very little room for other content.

max-w-64 (Tailwind v3.3+, or max-w-[256px] in earlier versions) sets max-width: 256px — the element can be as narrow as its content or parent requires, but can never exceed 256px. On a 200px parent it will be 200px; on a 1000px parent it will be 256px. This is responsive by design without any breakpoint classes.

min-w-0 sets min-width: 0px, overriding the browser's default of min-width: auto on flex items. By default, flex items can never shrink below the intrinsic width of their content — a long URL or a code string will push the flex item wider and overflow the container.

The fix is to add min-w-0 to the wrapper of the overflowing content. This tells the flex item it's allowed to shrink to zero width, at which point CSS overflow properties (overflow-hidden, truncate) can take effect and clip the text correctly. Always add it to the wrapper div, not the text element itself.

min-h-screen uses 100vh — the fixed viewport height that includes the space behind the mobile browser's address bar. On a short-content page on iOS or Android, the footer may appear slightly above the visible bottom of the screen when the address bar is shown.

min-h-dvh uses 100dvh — the Dynamic Viewport Height that adapts as the mobile address bar shows and hides. For the sticky footer pattern this is the correct choice: min-h-dvh flex flex-col. Use min-h-screen only when you know the layout is desktop-only, or when browser support for dvh is a concern (though it's widely supported since 2023).

max-w-prose sets max-width: 65ch — 65 character widths at the current font size. Research in typography consistently shows that 60–75 characters per line is the most comfortable reading line length for body text.

Unlike rem-based values like max-w-2xl (42rem), max-w-prose automatically adapts if you change the font size — a 20px body font gets a wider prose container than a 16px font. Use it on <article>, <p class="max-w-prose">, or any long-form text content — blog posts, documentation, tutorials — to keep lines comfortably readable at all screen sizes.

All min/max utilities accept the five breakpoint prefixes: sm: (640px+), md: (768px+), lg: (1024px+), xl: (1280px+), 2xl: (1536px+). Classes without a prefix apply at all sizes; prefixed classes apply at that breakpoint and above.

The progressive container pattern — max-w-full sm:max-w-xl lg:max-w-5xl mx-auto — starts at full viewport width on mobile (no constraint), constrains to 576px on small tablets, and settles at 1024px on desktop. This single class string replaces three media queries and adapts automatically. The same approach works for max-h: max-h-48 md:max-h-64 lg:max-h-96 overflow-y-auto gives a taller panel on larger screens.

MCQ Quiz — Test Yourself

Select the best answer. Correct answers are revealed on click.

Question 1 of 4
Which class combination creates a centred page container capped at ~1024px?
Question 2 of 4
A long URL is overflowing a flex child even though you added truncate. What is the correct fix?
Question 3 of 4
Which pattern correctly creates a sticky footer that always sits at the bottom of the page?
Question 4 of 4
What does max-w-prose set and why is it special compared to max-w-2xl?

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel