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.
h-4,
h-16, h-32, h-64
h-screen,
h-dvh (mobile-safe), h-svh
h-full correctly — only works when the parent
has a defined height
min-h-dvh flex flex-col + main gets
flex-1
max-h-64 overflow-y-auto
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.
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.
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.
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-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.
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.
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-64 md:h-auto.
h-dvh.
h-svh when you need guaranteed
no-overflow; use h-lvh for immersive experiences.
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-[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.
<!-- 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.
<!-- ❌ 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>
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.
overflow-y-auto inside flex layouts — a common
scrollable sidebar fix).
h-screen because the page won't
clip when there is more content. Pair with
min-h-dvh for the mobile-safe version.
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 = 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.
img class="max-h-full w-auto" keeps images inside
their container without stretching.
overflow-y-auto so the panel scrolls
internally while the page stays fixed:
class="max-h-screen overflow-y-auto".
<!-- ✅ 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>
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.
<!-- ✅ 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>
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
-
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-fullon a child whose parent has no defined height — it silently does nothing. -
h-screen vs h-dvh —
h-screen = 100vhclips on mobile when the address bar is visible.h-dvh = 100dvhadapts dynamically. For any full-screen section that must work on mobile, preferh-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). Useh-svhwhen guaranteed no-overflow is critical. -
Sticky footer pattern —
min-h-dvh flex flex-colon the page wrapper +flex-1on<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-colon each card +flex-1on the description +mt-autoon 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.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.