Control layout width, centering, padding and margin with Tailwind utilities.
container
Class
The container class sets
max-width to match the current breakpoint. Add
mx-auto to center it and
px-4 for horizontal
padding:
<div class="container mx-auto px-4">
Your centered content here
</div>
.container centers automatically. Tailwind requires
mx-auto explicitly. This gives you more control.
Use
max-w-{size} to constrain
element widths. Combine with
mx-auto to center:
max-w-xs (320px)
max-w-sm (384px)
max-w-md (448px)
max-w-lg (512px)
max-w-xl (576px)
max-w-full (100%)
The container class
automatically sets max-width at each breakpoint:
| Breakpoint | Min Width | Container Max-Width |
|---|---|---|
| none (xs) | 0px | 100% |
| sm: | 640px | 640px |
| md: | 768px | 768px |
| lg: | 1024px | 1024px |
| xl: | 1280px | 1280px |
| 2xl: | 1536px | 1536px |
Tailwind uses shorthand:
{property}{sides}-{size}
p = Padding (all sides)
m = Margin (all sides)t = topb = bottoml = leftr = rightx = horizontal (left + right)
y = vertical (top + bottom)
| Class | CSS Value | Pixels |
|---|---|---|
| p-0 / m-0 | 0 | 0px |
| p-1 / m-1 | 0.25rem | 4px |
| p-2 / m-2 | 0.5rem | 8px |
| p-4 / m-4 | 1rem | 16px |
| p-6 / m-6 | 1.5rem | 24px |
| p-8 / m-8 | 2rem | 32px |
| mx-auto | Centers block |