Responsive Design with Breakpoint Prefixes
What you'll learn: How to use Tailwind's breakpoint prefixes (sm:, md:, lg:, xl:) to create mobile-first responsive layouts without writing media queries.
The Mobile-First Mindset
In Tailwind, unprefixed utilities apply to all screen sizes by default. Breakpoint prefixes let you override those styles at specific viewport widths. Think of it like layers of paint: you start with the base mobile coat, then add larger-screen touches on top.
The breakpoints are:
sm:— 640px and up (small tablets)md:— 768px and up (tablets)lg:— 1024px and up (laptops)xl:— 1280px and up (desktops)
How It Works
Start by styling for mobile, then progressively enhance for larger screens:
<div className="p-4 md:p-8 lg:p-12">
{/* Padding: 1rem on mobile, 2rem on tablets, 3rem on laptops */}
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
{/* 1 column mobile, 2 columns small tablets, 4 columns laptops */}
<Card />
<Card />
<Card />
<Card />
</div>
<h1 className="text-2xl md:text-4xl lg:text-6xl font-bold">
{/* Font size grows with viewport */}
</h1>
You can combine multiple responsive utilities on a single element. The cascade applies: larger breakpoints override smaller ones, which override the base.
The Analogy
Think of building a house: the base classes are your foundation (works everywhere), then you add rooms (sm:), then a second floor (md:), then a fancy rooftop deck (lg:). Each addition builds on what came before.
Key Takeaway: Tailwind's breakpoint prefixes enable mobile-first responsive design by stacking viewport-specific styles — start with mobile defaults, then layer on sm:, md:, lg:, and xl: modifiers to adapt your layout progressively.