Tailwind Responsive Breakpoints
Responsive design means your webpage looks good on all screen sizes — mobile, tablet, and desktop. Tailwind CSS makes this simple using breakpoint prefixes.
What Is a Breakpoint?
A breakpoint is a screen width at which your layout changes. Think of it as a "switch point" — below this width, use one style; above it, use another.
Imagine a water pipe with valves at different points. Each valve controls what happens after a certain width:
Screen Width ──────────────────────────────────────────▶
320px 640px 768px 1024px 1280px 1536px
| | | | | |
(xs) (sm) (md) (lg) (xl) (2xl)
▼ ▼ ▼ ▼ ▼ ▼
Mobile Small Tablet Laptop Desktop Large
The Five Default Breakpoints in Tailwind
Tailwind comes with five built-in breakpoints. Each prefix activates the style only when the screen reaches that width or wider.
| Prefix | Minimum Width | Device Target |
|---|---|---|
sm: | 640px | Small phones (landscape) and up |
md: | 768px | Tablets and up |
lg: | 1024px | Laptops and up |
xl: | 1280px | Desktops and up |
2xl: | 1536px | Large screens and up |
How Breakpoints Work (Mobile-First)
Tailwind follows a mobile-first approach. A class without any prefix applies to all screen sizes. A prefixed class applies only at that width and above.
Mental Model Diagram
No prefix → applies everywhere (mobile and up) sm: → applies at 640px and above md: → applies at 768px and above lg: → applies at 1024px and above Example: text-sm md:text-base lg:text-lg Mobile(320px) → text-sm (small text) Tablet(768px) → text-base (base text) Desktop(1024px) → text-lg (large text)
Your First Responsive Class
Change text size based on screen width:
<p class="text-sm md:text-base lg:text-xl">
Hello, World!
</p>On mobile, the text is small. On tablets, it becomes base size. On laptops, it grows to extra-large.
Responsive Width Example
<div class="w-full md:w-1/2 lg:w-1/3">
I am a box
</div>What This Does:
Mobile: [====== Full Width ======] Tablet: [=== Half Width ===][ empty ] Desktop: [= One Third =][ empty ][ empty ]
Responsive Background Color
<div class="bg-blue-200 md:bg-green-200 lg:bg-yellow-200">
My color changes with screen size
</div>- Mobile → blue background
- Tablet → green background
- Desktop → yellow background
Responsive Display Toggle
Hide or show elements on specific screen sizes:
<!-- Only visible on mobile -->
<div class="block md:hidden">Mobile Menu</div>
<!-- Only visible on tablets and above -->
<div class="hidden md:block">Desktop Menu</div>Visibility Diagram:
Screen Size | Mobile Menu | Desktop Menu -------------|-------------|------------- Mobile | VISIBLE | HIDDEN Tablet/Above | HIDDEN | VISIBLE
Responsive Flex Direction
<div class="flex flex-col md:flex-row">
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
</div>Mobile (flex-col): Tablet (flex-row): ┌─────────┐ ┌──────┬──────┬──────┐ │ Box 1 │ │ Box1 │ Box2 │ Box3 │ ├─────────┤ └──────┴──────┴──────┘ │ Box 2 │ ├─────────┤ │ Box 3 │ └─────────┘
Responsive Grid Columns
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
</div>Mobile (1 col): Tablet (2 cols): Desktop (4 cols): ┌──────────┐ ┌─────┬─────┐ ┌──┬──┬──┬──┐ │ Item 1 │ │ 1 │ 2 │ │1 │2 │3 │4 │ ├──────────┤ ├─────┼─────┤ └──┴──┴──┴──┘ │ Item 2 │ │ 3 │ 4 │ ├──────────┤ └─────┴─────┘ │ Item 3 │ ├──────────┤ │ Item 4 │ └──────────┘
Stacking Multiple Responsive Classes
You can stack as many breakpoint prefixes as needed on any utility:
<div class="p-2 sm:p-4 md:p-6 lg:p-8 xl:p-10">
Padding grows with screen size
</div>Common Mistakes to Avoid
Mistake 1: Thinking unprefixed classes only apply on mobile
An unprefixed class applies on ALL screen sizes. It is the default. Prefixed classes override it at larger widths.
Mistake 2: Using max-width thinking
Tailwind breakpoints use min-width (mobile-first), not max-width. md:text-lg means "large text at 768px AND ABOVE," not "only on tablets."
Mistake 3: Skipping breakpoints
You do not need to set every breakpoint. Use only the ones where your design actually changes.
Quick Reference: Breakpoint Cheat Sheet
Utility Pattern: [breakpoint]:[utility-class] Examples: - sm:flex → flex layout from 640px up - md:hidden → hidden from 768px up - lg:grid-cols-3 → 3-column grid from 1024px up - xl:text-2xl → 2xl text from 1280px up - 2xl:max-w-7xl → max width from 1536px up
Real Page Example: Product Card
<div class="flex flex-col md:flex-row bg-white shadow p-4 gap-4">
<img src="product.jpg" class="w-full md:w-48 rounded">
<div>
<h2 class="text-lg lg:text-2xl font-bold">Product Name</h2>
<p class="text-sm md:text-base text-gray-600">Description here</p>
<button class="mt-2 bg-blue-500 text-white px-4 py-2 rounded">
Buy Now
</button>
</div>
</div>Mobile Layout: Desktop Layout: ┌──────────────┐ ┌────────┬──────────────────────┐ │ [Image] │ │ │ Product Name (big) │ │ │ │[Image] │ Description text │ │ Product Name │ │ │ [Buy Now] │ │ Description │ └────────┴──────────────────────┘ │ [Buy Now] │ └──────────────┘
Summary
- Tailwind uses five breakpoints:
sm,md,lg,xl,2xl - All breakpoints apply at that width and above (min-width / mobile-first)
- Unprefixed classes are the default for all screen sizes
- Stack multiple breakpoint prefixes on a single element as needed
- Use
block/hiddento show or hide content at specific breakpoints
