Loading lessons...
Width & Height
Width & Height
Size elements with width and height utilities.
Width
| Class | CSS |
|---|---|
w-<n> | spacing scale: w-64 = 16rem |
w-1/2, w-2/3, w-3/4 | percentage |
w-full | 100% |
w-screen | 100vw |
w-svw, w-lvw, w-dvw | viewport units |
w-auto | auto |
w-fit, w-min, w-max | fit-content, min-content, max-content |
<div class="w-1/2">Half width</div>
<div class="w-full">Full width</div>
Max width
Control how wide an element can get:
| Class | CSS |
|---|---|
max-w-xs | 20rem |
max-w-sm | 24rem |
max-w-md | 28rem |
max-w-lg | 32rem |
max-w-xl | 36rem |
max-w-2xl … max-w-7xl | 42-80rem |
max-w-full | 100% |
max-w-prose | 65ch |
max-w-md mx-auto is the classic centered container pattern.
Min width
min-w-0, min-w-<n>, min-w-full, min-w-fit, min-w-min, min-w-max.
Height
Same pattern as width:
h-<n>- spacing scale.h-1/2,h-2/3- percentages.h-full,h-screen,h-svh,h-dvh.h-auto,h-fit,h-min,h-max.min-h-,max-h-exist too.
Box size shorthand
size-<n> sets both width and height:
<img class="size-12" src="..." alt="..." />
TL;DR
w-64uses the spacing scale;w-1/2uses percentages.w-full,h-screen,min-h-screenare common.max-w-md mx-autocenters a container.size-12sets both dimensions.