Tailwind Sizing
Sizing utilities set an element's width, height, their minimum and maximum limits, and its aspect ratio.
Width and height
| Class | Value |
|---|---|
w-16 / h-16 |
spacing scale: 4rem (64px) |
w-1/2, w-1/3, w-3/4 … |
a fraction of the parent: 50%, 33.33%, 75% |
w-full / h-full |
100% of the parent |
w-screen / h-screen |
100vw / 100vh |
h-dvh / w-dvw |
dynamic viewport units (better on mobile browsers) |
w-auto |
browser default |
w-fit / w-min / w-max |
fit-content / min-content / max-content |
size-10 |
width and height at once |
html · try it yourself
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="space-y-2 p-4 text-xs text-white">
<div class="w-full rounded bg-indigo-700 p-1">w-full</div>
<div class="w-3/4 rounded bg-indigo-600 p-1">w-3/4</div>
<div class="w-1/2 rounded bg-indigo-500 p-1">w-1/2</div>
<div class="w-1/3 rounded bg-indigo-400 p-1">w-1/3</div>
<div class="w-fit rounded bg-indigo-300 p-1 text-indigo-900">w-fit — only as wide as my text</div>
<div class="flex gap-2">
<div class="size-8 rounded bg-teal-500"></div>
<div class="size-12 rounded bg-teal-500"></div>
<div class="size-16 rounded bg-teal-500"></div>
</div>
</body>
</html>Note:
size-*arrived in v3.4 and is the idiomatic way to size square things such as icons and avatars in v4 —size-10instead ofw-10 h-10.
Max width: keeping content readable
max-w-* stops an element from growing beyond a limit. Named sizes come from the container scale:
| Class | Value | Class | Value |
|---|---|---|---|
max-w-xs |
20rem (320px) | max-w-2xl |
42rem (672px) |
max-w-sm |
24rem (384px) | max-w-4xl |
56rem (896px) |
max-w-md |
28rem (448px) | max-w-7xl |
80rem (1280px) |
max-w-lg |
32rem (512px) | max-w-prose |
65ch (ideal line length) |
max-w-xl |
36rem (576px) | max-w-full / max-w-none |
100% / no limit |
html · try it yourself
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="bg-stone-100 p-4">
<article class="mx-auto max-w-sm rounded-xl bg-white p-5 shadow">
<h2 class="font-bold">max-w-sm + mx-auto</h2>
<p class="mt-2 text-sm text-stone-600">Drag the preview wider: this card stops at 24rem and stays centred, while on a narrow screen it simply fills the width.</p>
</article>
</body>
</html>Min width and min/max height
| Class | Typical use |
|---|---|
min-h-screen / min-h-dvh |
a page that is at least as tall as the window |
min-w-0 |
let a flex child shrink below its content size (fixes overflowing text) |
max-h-48 overflow-y-auto |
a scrollable list with a fixed maximum height |
min-w-32 |
buttons that never get too narrow |
html · try it yourself
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-4">
<ul class="max-h-40 w-60 divide-y divide-gray-200 overflow-y-auto rounded-lg border border-gray-300">
<li class="p-2">🍎 Apple</li><li class="p-2">🍌 Banana</li><li class="p-2">🍒 Cherry</li>
<li class="p-2">🥝 Kiwi</li><li class="p-2">🍋 Lemon</li><li class="p-2">🥭 Mango</li>
<li class="p-2">🍑 Peach</li><li class="p-2">🍐 Pear</li>
</ul>
<p class="mt-2 text-sm text-gray-500">max-h-40 + overflow-y-auto: scroll the list.</p>
</body>
</html>Aspect ratio
| Class | Ratio |
|---|---|
aspect-square |
1 / 1 |
aspect-video |
16 / 9 |
aspect-3/2, aspect-4/3 … |
any fraction (new in v4) |
aspect-auto |
the element's natural ratio |
html · try it yourself
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="grid grid-cols-3 items-start gap-3 p-4 text-sm font-semibold text-white">
<div class="flex aspect-square items-center justify-center rounded-lg bg-orange-500">square</div>
<div class="flex aspect-video items-center justify-center rounded-lg bg-orange-600">video</div>
<div class="flex aspect-3/4 items-center justify-center rounded-lg bg-orange-700">3/4</div>
</body>
</html>Aspect ratios are perfect for video embeds and image placeholders: give the element a width (w-full) and the height follows automatically.
Tip: Avoid fixed heights on text containers (
h-40) — content may overflow. Prefermin-h-*so the box can grow.
Test yourself
Which class sets both width and height to 3rem?
wh-12size-12square-12w-12/h-12
What does w-2/3 produce?
- width: 2/3rem
- width: 66.666667%
- width: 23px
- two thirds of the viewport
Which combination keeps a page section at least as tall as the browser window?
h-fullmin-h-screenmax-h-screenaspect-screen