min-width vs max-width Strategies
You'll learn how to choose between mobile-first (min-width) and desktop-first (max-width) media query approaches for responsive design.
The Core Difference
When writing media queries, you have two main strategies:
Mobile-First (min-width): Start with styles for small screens, then add media queries that apply when the screen is at least a certain width. You're progressively adding complexity as screens get larger.
Desktop-First (max-width): Start with styles for large screens, then add media queries that apply when the screen is at most a certain width. You're progressively simplifying as screens get smaller.
Mobile-First with min-width
/* Base styles: mobile (no media query needed) */
.container {
padding: 1rem;
font-size: 16px;
}
/* Tablet and up (applies at 768px AND ABOVE) */
@media (min-width: 768px) {
.container {
padding: 2rem;
font-size: 18px;
}
}
/* Desktop and up (applies at 1024px AND ABOVE) */
@media (min-width: 1024px) {
.container {
padding: 3rem;
font-size: 20px;
}
}
Desktop-First with max-width
/* Base styles: desktop (no media query needed) */
.container {
padding: 3rem;
font-size: 20px;
}
/* Tablet and down (applies at 1023px AND BELOW) */
@media (max-width: 1023px) {
.container {
padding: 2rem;
font-size: 18px;
}
}
/* Mobile (applies at 767px AND BELOW) */
@media (max-width: 767px) {
.container {
padding: 1rem;
font-size: 16px;
}
}
When to Use Each
Prefer min-width (mobile-first) in most cases—it aligns with progressive enhancement, performs better on mobile devices (which load the base styles first), and matches how most users browse today.
Use max-width (desktop-first) when retrofitting older desktop-only sites or when your primary audience uses desktops.
Key Takeaway: Mobile-first with min-width builds complexity upward as screens grow, while desktop-first with max-width strips complexity downward—mobile-first is the modern best practice.