Responsive Design
Every Tailwind utility can be applied at a specific screen size by adding a breakpoint prefix. This is how you make one page work on phones, tablets and desktops without writing media queries.
Mobile first
Tailwind is mobile-first: an unprefixed class applies at every size, and a prefixed class applies from that breakpoint upwards.
| Prefix | Minimum width | CSS |
|---|---|---|
| (none) | 0 | always |
sm: |
40rem (640px) | @media (width >= 40rem) |
md: |
48rem (768px) | @media (width >= 48rem) |
lg: |
64rem (1024px) | @media (width >= 64rem) |
xl: |
80rem (1280px) | @media (width >= 80rem) |
2xl: |
96rem (1536px) | @media (width >= 96rem) |
So text-sm md:text-lg means: small text on phones, large text from 768px up.
Note:
sm:does not mean "on small screens". It means "at 640px and wider". Style phones with unprefixed classes, then override for bigger screens.
Drag the preview pane's edge in these examples to see them respond.
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-4">
<div class="rounded-xl bg-red-500 p-6 text-center text-xl font-bold text-white sm:bg-amber-500 md:bg-emerald-500 lg:bg-sky-500">
<span class="sm:hidden">base (< 640px)</span>
<span class="hidden sm:inline md:hidden">sm: (≥ 640px)</span>
<span class="hidden md:inline lg:hidden">md: (≥ 768px)</span>
<span class="hidden lg:inline">lg: (≥ 1024px)</span>
</div>
</body>
</html>Responsive layouts
The most common pattern: stack on mobile, go side by side on larger screens.
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="bg-slate-100 p-4">
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-4">
<div class="rounded-lg bg-white p-4 shadow-sm">📦 Orders</div>
<div class="rounded-lg bg-white p-4 shadow-sm">💰 Revenue</div>
<div class="rounded-lg bg-white p-4 shadow-sm">👥 Customers</div>
<div class="rounded-lg bg-white p-4 shadow-sm">⭐ Reviews</div>
</div>
<div class="mt-3 flex flex-col gap-3 md:flex-row">
<div class="rounded-lg bg-indigo-500 p-4 text-white md:w-1/3">Sidebar: full width on mobile, 1/3 on md+</div>
<div class="flex-1 rounded-lg bg-white p-4 shadow-sm">Main content</div>
</div>
</body>
</html>Targeting ranges with max-*
Combine a breakpoint with a max-* variant to apply styles only within a range:
| Class | Applies when |
|---|---|
max-md:hidden |
width below 768px |
md:max-lg:flex |
from 768px up to (not including) 1024px |
max-sm:text-center |
below 640px |
Custom breakpoints
Add or change breakpoints in your theme with --breakpoint-* variables (more on @theme later). For a one-off value use an arbitrary breakpoint: min-[900px]:grid-cols-3 or max-[500px]:p-2.
@import "tailwindcss";
@theme {
--breakpoint-xs: 30rem; /* adds an xs: variant */
--breakpoint-3xl: 120rem; /* adds a 3xl: variant */
}Container queries (built in to v4)
Breakpoints react to the viewport. Container queries react to the size of a parent element, which is perfect for reusable components that may sit in a narrow sidebar or a wide main area. Mark the parent with @container, then use @sm:, @md:, @lg: … on children.
| Class | Container width |
|---|---|
@xs: |
≥ 20rem (320px) |
@sm: |
≥ 24rem (384px) |
@md: |
≥ 28rem (448px) |
@lg: |
≥ 32rem (512px) |
@max-md: |
below 28rem |
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex gap-3 p-4">
<div class="@container w-48 shrink-0">
<div class="flex flex-col gap-2 rounded-lg bg-white p-3 shadow ring-1 ring-slate-200 @sm:flex-row">
<div class="flex h-16 items-center justify-center rounded bg-teal-400 text-2xl @sm:w-24">🐢</div>
<p class="text-sm">Narrow container: stacked.</p>
</div>
</div>
<div class="@container flex-1">
<div class="flex flex-col gap-2 rounded-lg bg-white p-3 shadow ring-1 ring-slate-200 @sm:flex-row">
<div class="flex h-16 items-center justify-center rounded bg-teal-400 text-2xl @sm:w-24">🐢</div>
<p class="text-sm">Same component in a wider container: side by side.</p>
</div>
</div>
</body>
</html>Note: In v3 container queries needed the
@tailwindcss/container-queriesplugin. In v4 they're part of the core.
Tip: Always include
<meta name="viewport" content="width=device-width, initial-scale=1">in real pages, or phones will render a zoomed-out desktop layout and your breakpoints won't behave as expected.
Test yourself
What does md:flex mean?
display: flexonly on medium screensdisplay: flexat 768px and widerdisplay: flexbelow 768px- A medium-sized flex gap
You want a 1-column grid on phones and 3 columns from 1024px. Which classes?
grid-cols-3 sm:grid-cols-1grid grid-cols-1 lg:grid-cols-3grid lg:grid-cols-1 grid-cols-3grid max-lg:grid-cols-3
What must you add to a parent before children can use @md: variants?
container@containerrelativemd:container