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).
min-w-0,
min-w-full, min-w-min,
min-w-fit
max-w-sm through
max-w-screen-2xl and max-w-prose
min-w-0 on
flex children
min-h-dvh flex flex-col for the sticky footer
page layout pattern
max-h-64 overflow-y-auto
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.
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-5xl mx-auto is the
universal centred page container. Also sets reading widths
(max-w-prose) and modal
widths (max-w-lg).
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.
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.
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.
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 + overflow-hidden or
truncate on the flex child to clip text
correctly.
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.
<!-- ❌ 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>
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.
fixed inset-0 flex items-center justify-center
for modal overlays.
max-w-prose targets (65ch). Use for blog posts,
articles, and documentation pages.
mx-auto px-4 for
centring and gutters.
img class="max-w-full h-auto" ensures images
never overflow their container at any screen width.
<!-- ✅ 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">
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.
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.
<body class="min-h-dvh flex flex-col">.
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 = 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-[90vh] overflow-y-auto leaves a comfortable
margin at the top and bottom while allowing internal
scrolling.
max-h-screen on
mobile: use max-h-dvh overflow-y-auto on modal
inner content.
<!-- 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>
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.
<!-- 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>
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
-
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: autowhich prevents them shrinking below content size.min-w-0removes that default sotruncateandoverflow-hiddenwork 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-1on<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-0removes that constraint and allowsoverflow-y-autoto 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-autoprogressively 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.
truncate. What is the correct fix?
max-w-prose
set and why is it special compared to
max-w-2xl?
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.