Ch 20 / 45
Chapter 20 Beginner 5 min read Tailwind CSS

Height in Tailwind CSS

Height utilities in Tailwind control how tall an element renders. The system has four groups: fixed pixel heights using the 4px scale (h-64 = 256px), viewport heights (h-screen, h-dvh, h-svh) for full-screen sections, content-based heights (h-auto, h-full) that adapt to content or parent, and constraint utilities (min-h-*, max-h-*) for sticky footers and scrollable panels. The single most common gotcha: h-full only works when the parent has a defined height.

Advertisement
Google Ad Placeholder · 728×90 Leaderboard
What you'll learn
Set fixed pixel heights with the 4px scale: h-4, h-16, h-32, h-64
Create full-screen sections with h-screen, h-dvh (mobile-safe), h-svh
Use h-full correctly — only works when the parent has a defined height
Build sticky footers with min-h-dvh flex flex-col + main gets flex-1
Create scrollable panels capped at a fixed height: max-h-64 overflow-y-auto
Build equal-height cards using h-full + flex flex-col + mt-auto CTA

What is Height? — Four Sizing Groups

Every HTML element has a natural height — it grows to contain its children by default. Tailwind's h-* utilities let you override that with precision. Like width, height utilities fall into four groups, each designed for a different use case: fixed scale for icons and UI chrome, viewport units for full-screen layouts, content-relative values for flexible containers, and min/max constraints for adaptive panels.

Four height groups — each solves a different layout problem 1. Fixed heights — 4px scale h-12 48px h-20 80px h-32 128px class number × 4 = px 2. Viewport heights h-screen 100vh address bar h-dvh 100dvh address bar ✓ fits h-screen (clips) h-dvh (safe) 3. Content-based h-auto grows to fit content (browser default) h-full 100% of parent* *parent must have height or use flex/grid parent 4. min-h & max-h min-h-screen at least 100dvh can grow beyond max-h-64 cap at 256px + overflow-y-auto sticky footer / scrollable panel Use fixed for icons • viewport for hero sections • h-auto/h-full for flex children • min-h/max-h for layout patterns
Fixed Scale
h-1–h-96: same formula as padding and margin — class number × 4 = pixels. h-16 = 64px, h-32 = 128px, h-64 = 256px. Use for icons, avatars, dividers, and fixed-height navigation bars.
Viewport Heights
h-screen (100vh), h-dvh (100dvh — dynamic, mobile-safe), h-svh (100svh — small viewport), h-lvh (100lvh — large viewport). Use for hero sections, full-screen modals, and splash pages. Prefer h-dvh over h-screen on mobile.
Content-based
h-auto — browser default (grows to fit children). h-full — 100% of the parent's height. h-full only works when the parent has a defined height — either an explicit value (h-64), a viewport unit (h-screen), or a flex/grid parent.
min-h & max-h
min-h-screen / min-h-dvh — at least full viewport, can grow. max-h-64 / max-h-96 — cap height and add overflow-y-auto for scrollable panels. These two patterns cover 90% of real-world height problems.
The h-full gotcha h-full sets height: 100% — but that percentage is of the parent's height. If the parent has no defined height (which is the default for block elements), h-full has no effect. The fix: give the parent an explicit height (h-64, h-screen, h-dvh), or make it a flex/grid container — flex children can use h-full because the flex algorithm assigns them a definite height in the cross axis.
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

All Height Utilities — Complete Reference

Every h-* class maps to a specific CSS height value. Here are the key categories from the fixed 4px scale to the modern dynamic viewport units.

h-auto
height: auto — The CSS default. The element grows to contain its children. Use when you want the browser to manage the height naturally. Also used to reset a fixed height applied by a smaller breakpoint: h-64 md:h-auto.
h-full
height: 100% — 100% of the parent's computed height. Requires a parent with a defined height. Works reliably inside flex/grid containers, or when the parent has an explicit height class or viewport-based height. Most commonly used to stretch card content, fill sidebar columns, or size children inside a fixed-height container.
h-screen
height: 100vh — 100% of the browser viewport's visible height. On desktop this works well. On mobile browsers the 100vh includes the height behind the retractable address bar, causing content to be clipped. For mobile-safe full-screen layouts, prefer h-dvh.
h-dvh
height: 100dvh — Dynamic Viewport Height. Adapts in real time as the mobile browser's address bar shows or hides. The modern default for any full-screen section that must work correctly on both iOS and Android. Supported in all modern browsers since 2023.
h-svh / h-lvh
h-svh = 100svh (Small Viewport) — uses the height when the browser chrome is fully shown (most conservative, always fits). h-lvh = 100lvh (Large Viewport) — uses the height when the browser chrome is hidden (tallest possible). Use h-svh when you need guaranteed no-overflow; use h-lvh for immersive experiences.
h-0 … h-96
Fixed pixel heights (4px scale) — Formula: class number × 4 = pixels. h-4 = 16px, h-16 = 64px, h-32 = 128px, h-64 = 256px. Use for navbar height (h-16), icon containers (h-12), hero images, and any element needing an exact pixel height.
h-[N]
Arbitrary value — h-[400px], h-[50vh], h-[calc(100vh-64px)]. Any valid CSS height inside square brackets. Use when the scale doesn't hit the exact height a design specifies, or for common patterns like h-[calc(100vh-64px)] for content below a 64px navbar.
HTML — essential height utilities in action
<!-- h-16: fixed-height navbar (64px) -->
<nav class="h-16 flex items-center px-6 bg-gray-900 border-b border-gray-800">
  Logo + links
</nav>

<!-- h-12: square icon container (48px) -->
<div class="h-12 w-12 rounded-xl bg-cyan-600 flex items-center justify-center">
  <iconify-icon icon="solar:star-bold" width="24"></iconify-icon>
</div>

<!-- h-dvh: full-screen hero section (mobile-safe) -->
<section class="h-dvh flex items-center justify-center bg-gradient-to-br
             from-slate-900 to-cyan-950">
  <h1 class="text-5xl font-bold text-white text-center">Hero Section</h1>
</section>

<!-- h-full inside a flex parent (works!) -->
<div class="flex h-64">
  <aside class="h-full w-48 bg-gray-800 p-4">Sidebar fills parent height</aside>
  <main  class="h-full flex-1 bg-gray-700 p-4">Main fills parent height</main>
</div>

<!-- h-[calc()]: content below fixed navbar -->
<div class="h-[calc(100vh-64px)] overflow-y-auto">
  Scrollable content that fills viewport below 64px navbar
</div>

Viewport Heights & the h-dvh Fix

h-screen has been the standard full-height utility for years, but it has a well-known bug on mobile: 100vh includes the space occupied by the browser's retractable address bar. When the address bar is visible, the bottom of a h-screen section is hidden behind it. The CSS specification introduced three new viewport units to fix this: dvh, svh, and lvh. Tailwind maps all of them.

Mobile viewport units — how they handle the browser address bar h-screen (100vh) — CLIPS h-dvh (100dvh) — FITS h-svh (100svh) — SAFE h-lvh (100lvh) — LARGE 9:41 k2infocom.com h-screen 100vh ⚠ content hidden behind address bar 9:41 k2infocom.com h-dvh 100dvh ✓ perfectly fits visible area 9:41 k2infocom.com h-svh 100svh most conservative never overflows 9:41 h-lvh 100lvh bar hidden tallest possible Recommendation: use h-dvh for modern mobile-safe full-screen sections. Use h-svh only when you need guaranteed no-overflow.
HTML — viewport height comparison: h-screen vs h-dvh
<!-- ❌ h-screen: clips on mobile when address bar is visible -->
<section class="h-screen flex items-center justify-center">
  Bottom may be hidden on iOS / Android
</section>

<!-- ✅ h-dvh: the modern mobile-safe replacement -->
<section class="h-dvh flex items-center justify-center
             bg-gradient-to-br from-slate-900 to-cyan-950">
  <div class="max-w-2xl mx-auto px-4 text-center">
    <h1 class="text-5xl font-bold text-white mb-4">Hero Section</h1>
    <p class="text-gray-400 text-lg">Perfectly fills the visible screen on any device</p>
  </div>
</section>

<!-- h-svh: most conservative, use when no-overflow is critical -->
<div class="h-svh overflow-hidden">
  Always visible, even with browser chrome at max size
</div>

<!-- Multi-section scrolling page: each section fills viewport -->
<main>
  <section class="h-dvh snap-start flex items-center justify-center bg-slate-900">Section 1</section>
  <section class="h-dvh snap-start flex items-center justify-center bg-slate-800">Section 2</section>
  <section class="h-dvh snap-start flex items-center justify-center bg-slate-700">Section 3</section>
</main>
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

min-h & max-h — Sticky Footers & Scrollable Panels

min-h-* sets a minimum height — the element can be taller but never shorter. max-h-* sets a maximum height — the element can be shorter but never taller (combine with overflow-y-auto for a scrollable panel). These two utilities power the two most common height patterns in modern web layouts: the sticky footer and the scrollable content panel.

Two patterns — sticky footer (min-h) and scrollable panel (max-h) Pattern A — Sticky Footer min-h-dvh flex flex-col header (h-16, fixed) main (flex-1) grows to fill remaining space pushes footer to bottom footer (always at bottom) Without flex-1, footer sticks to content on short pages Pattern B — Scrollable Panel max-h-64 overflow-y-auto Notification 1 Notification 2 Notification 3 Notification 4 (cut off) Notification 5 (hidden, scroll) Content inside can be much taller — user scrolls within the panel
min-h-0
min-height: 0px — Removes any minimum height constraint. Used to override browser defaults or when a flex child needs to shrink below its content size (e.g., to enable overflow-y-auto inside flex layouts — a common scrollable sidebar fix).
min-h-screen
min-height: 100vh — At least full viewport height, can grow if content is taller. Better for page-level wrappers than h-screen because the page won't clip when there is more content. Pair with min-h-dvh for the mobile-safe version.
min-h-dvh
min-height: 100dvh — Mobile-safe minimum viewport height. The ideal choice for the page root wrapper in the sticky footer pattern: class="min-h-dvh flex flex-col". Content can exceed 100dvh, and the footer always pins to the bottom on short-content pages.
max-h-32…96
Capped heights — max-h-32 = 128px, max-h-48 = 192px, max-h-64 = 256px, max-h-96 = 384px. The element cannot be taller than this. Combine with overflow-y-auto to make a scrollable panel. Use for notification lists, dropdown menus, log viewers, and expandable comment threads.
max-h-full
max-height: 100% — The element cannot be taller than its parent. Useful for images and media inside flex/grid cells: img class="max-h-full w-auto" keeps images inside their container without stretching.
max-h-screen
max-height: 100vh — Use for modals, drawers, and sidebars that should not exceed the viewport height. Combine with overflow-y-auto so the panel scrolls internally while the page stays fixed: class="max-h-screen overflow-y-auto".
HTML — sticky footer + scrollable panel patterns
<!-- ✅ STICKY FOOTER PATTERN -->
<body class="min-h-dvh flex flex-col">
  <header class="h-16 bg-gray-900 flex items-center px-6">
    Navbar
  </header>

  <main class="flex-1 px-6 py-12">
    <!-- flex-1 = flex-grow:1 = takes all remaining height -->
    Page content here. Footer always sits at the bottom.
  </main>

  <footer class="h-20 bg-gray-900 flex items-center justify-center">
    © 2025 K2infocom. Always at the bottom.
  </footer>
</body>

<!-- ✅ SCROLLABLE PANEL PATTERN -->
<div class="max-h-64 overflow-y-auto rounded-xl border border-gray-700
           divide-y divide-gray-700 bg-gray-800">
  <div class="px-4 py-3 text-sm">Notification 1</div>
  <div class="px-4 py-3 text-sm">Notification 2</div>
  <div class="px-4 py-3 text-sm">Notification 3</div>
  <div class="px-4 py-3 text-sm">Notification 4</div>
  <div class="px-4 py-3 text-sm">Notification 5</div>
</div>
<!-- Panel is 256px tall; anything beyond that is scrollable -->

<!-- ✅ SCROLLABLE MODAL / DRAWER -->
<div class="fixed inset-0 flex items-end sm:items-center justify-center p-4">
  <div class="w-full max-w-lg max-h-screen overflow-y-auto
           bg-gray-800 rounded-t-2xl sm:rounded-2xl p-6">
    Long modal content — scrolls inside if taller than viewport
  </div>
</div>
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

Practical Patterns — Equal Cards, Heroes & Responsive Heights

Height utilities shine in three real-world scenarios: making cards in a grid row all the same height, building responsive full-screen sections, and controlling sidebar height relative to a parent panel. Here are the production-ready patterns.

h-full
flex flex-col child
fills parent height
flex-1
grow to fill space
pushes mt-auto CTA
mt-auto
CTA at card bottom
equal-height cards
h-dvh
full screen section
mobile-safe
min-h-dvh
page wrapper
sticky footer
max-h-96
+ overflow-y-auto
scrollable panel
HTML — equal-height cards with h-full, flex flex-col, mt-auto
<!-- ✅ EQUAL-HEIGHT CARD GRID -->
<!-- Grid makes all rows the same height automatically -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">

  <!-- flex flex-col + h-full makes each card fill row height -->
  <div class="flex flex-col h-full bg-gray-800 rounded-2xl p-6">
    <div class="h-12 w-12 rounded-xl bg-cyan-600 flex items-center justify-center mb-4">
      <iconify-icon icon="solar:code-bold" width="24"></iconify-icon>
    </div>
    <h3 class="text-lg font-semibold text-white mb-2">Course Title</h3>
    <p class="text-gray-400 text-sm flex-1">
      Description text that may vary in length across cards.
      flex-1 pushes the button to the bottom.
    </p>
    <!-- mt-auto: button always at the bottom of every card -->
    <a href="#"
       class="mt-auto inline-flex items-center gap-2 text-cyan-400 text-sm
              font-semibold hover:text-cyan-300 transition">
      Enroll Now <iconify-icon icon="solar:arrow-right-linear" width="14"></iconify-icon>
    </a>
  </div>

  <!-- Repeat card 2, 3 with different description lengths -->
</div>

<!-- ✅ MULTI-SECTION PAGE: each fills viewport height -->
<div class="snap-y snap-mandatory h-dvh overflow-y-scroll">
  <section class="h-dvh snap-start flex items-center justify-center bg-slate-900">
    <h1 class="text-4xl font-bold text-white">Welcome</h1>
  </section>
  <section class="h-dvh snap-start flex items-center justify-center bg-cyan-950">
    <h2 class="text-4xl font-bold text-white">About</h2>
  </section>
</div>

<!-- ✅ SCROLLABLE SIDEBAR next to fixed content -->
<div class="flex h-[calc(100vh-64px)]">
  <aside class="w-64 h-full overflow-y-auto bg-gray-900 p-4">
    Long sidebar list...
  </aside>
  <main class="flex-1 h-full overflow-y-auto p-8">
    Main scrollable content
  </main>
</div>
Advertisement
Google Ad Placeholder · 728×90 Leaderboard

Quick Reference — All Height Utilities

Class CSS Property Notes
h-0 height: 0px Zero height — hide without display:none
h-px height: 1px Hairline divider
h-1 … h-96 N × 0.25rem 4px scale — same as padding/margin ★
h-auto height: auto Browser default — grows to fit children ★
h-full height: 100% 100% of parent (parent must have height) ★★
h-screen height: 100vh Full viewport — clips on mobile ★
h-dvh height: 100dvh Dynamic — mobile-safe (preferred) ★★
h-svh height: 100svh Small viewport — most conservative ★
h-lvh height: 100lvh Large viewport — tallest possible
h-fit height: fit-content Shrink-wrap to content height
h-min height: min-content Minimum content height
h-max height: max-content Maximum content height
h-[N] Custom Arbitrary: h-[400px], h-[calc(100vh-64px)] ★
min-h-0 min-height: 0 Remove min-height — enables overflow-y on flex ★
min-h-full min-height: 100% At least fills parent
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
max-h-32 … 96 N × 0.25rem Fixed cap — add overflow-y-auto ★★
max-h-full max-height: 100% Cap at parent height — use on 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-[500px]

★ = 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 Height Cheat Sheet
Free one-page cheat sheet covering all h-* utilities — fixed scale, viewport heights, h-dvh fix, sticky footer pattern, scrollable panels, and min-h/max-h with real examples.
h-full h-screen h-dvh h-svh min-h-dvh max-h + overflow Sticky Footer 4px Scale
Download Free Cheat Sheet
Chapter Summary
  • Four height groups — fixed scale (h-64 = 256px), viewport (h-screen, h-dvh, h-svh), content-based (h-auto, h-full), and constraint utilities (min-h-*, max-h-*). Each group solves a different layout scenario.
  • h-full = 100% of parent — only works when the parent has a defined height (explicit class, viewport unit, or flex/grid container). The most common height beginner mistake is using h-full on a child whose parent has no defined height — it silently does nothing.
  • h-screen vs h-dvh — h-screen = 100vh clips on mobile when the address bar is visible. h-dvh = 100dvh adapts dynamically. For any full-screen section that must work on mobile, prefer h-dvh.
  • h-svh and h-lvh — h-svh = 100svh (small viewport — most conservative, address bar fully shown). h-lvh = 100lvh (large viewport — address bar hidden, tallest). Use h-svh when guaranteed no-overflow is critical.
  • Sticky footer pattern — min-h-dvh flex flex-col on the page wrapper + flex-1 on <main>. The main content grows to fill available space, pushing the footer to the bottom even on pages with little content.
  • Scrollable panel pattern — max-h-64 overflow-y-auto. The panel is capped at 256px; anything beyond that scrolls inside it. Use for notification lists, dropdown menus, log viewers, and comment threads.
  • Equal-height cards — Use grid for the wrapper (rows are automatically equal height) + flex flex-col on each card + flex-1 on the description + mt-auto on the CTA button to pin it to the card bottom.
  • Next chapter — Min/Max Width & Height covers the full min-w-*, max-w-*, min-h-*, max-h-* specification in detail, including arbitrary constraints and responsive overrides.

Quick Check — Questions & Answers

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

h-full sets height: 100% — 100% of the element's parent container's height. It requires the parent to have a defined height. If the parent's height is not set (the browser default), h-full has no visible effect.

h-screen sets height: 100vh — 100% of the browser viewport height, regardless of the parent. It works anywhere without needing a defined parent height. The downside is that on mobile browsers 100vh includes the space behind the retractable address bar, which can clip content at the bottom. Use h-dvh instead for full-screen sections on mobile.

Use h-dvh (Dynamic Viewport Height) whenever you are building a full-screen section that must work correctly on mobile browsers — hero sections, splash screens, fullscreen modals, and vertical-scroll snap layouts.

h-screen = 100vh calculates the viewport height once and ignores the retractable address bar. When the address bar is visible on mobile, content at the bottom of the section is hidden behind it. h-dvh = 100dvh adapts in real-time as the bar shows and hides, always matching the currently visible area. Use h-screen only for desktop-only designs where you know mobile is not a concern.

min-h-screen sets min-height: 100vh — the page is at least 100vh tall, but can grow if the content is longer. h-screen sets an exact height of 100vh — if content is taller, it overflows or scrolls (depending on overflow settings).

For page-level wrappers, min-h-screen (or better, min-h-dvh) is almost always the right choice. It ensures a full-screen appearance on short-content pages while letting the page grow naturally on pages with lots of content. h-screen is the right choice only when you want strict full-viewport height with intentional overflow/scroll control.

Use a grid wrapper (grid rows are equal height by default) with flex flex-col on each card. Give the card's description or body area flex-1 so it stretches to fill the remaining space, then add mt-auto to the CTA button to push it to the bottom of every card regardless of description length.

Pattern: <div class="grid grid-cols-3 gap-6"> <div class="flex flex-col bg-gray-800 rounded-2xl p-6"> ... <p class="flex-1">Description</p> <a class="mt-auto btn">CTA</a> </div> </div>. The grid ensures the cards are the same row height; flex flex-col + flex-1 + mt-auto aligns the CTA at the bottom of each.

This combination creates a scrollable panel: the element is capped at a maximum height (e.g., max-h-64 = 256px), and any content beyond that height becomes scrollable inside the element rather than pushing the layout below it.

Common use cases: notification dropdowns, chat message lists, log viewers, expandable comment sections, dropdown selects with many options, and sidebar navigation with many items. The key benefit is that the panel occupies a predictable, bounded space on the page, while still giving the user access to all of the content through scrolling. Always pair with a border or shadow so users can tell the container is scrollable.

MCQ Quiz — Test Yourself

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

Question 1 of 4
Which class sets an element's height to exactly 100% of the browser viewport?
Question 2 of 4
On mobile, which height unit adapts dynamically as the browser address bar shows or hides?
Question 3 of 4
Which class combination creates a sticky footer that always stays at the bottom of the page?
Question 4 of 4
To create a notification panel capped at 256px with internal scrolling, which combination is correct?

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