Media queries give CSS the ability to "sense its environment" — selectively applying a set of style rules based on viewport width, device orientation, the user's system preferences, and more. They are the foundation of responsive design.
When the condition holds, the rules inside the braces take effect; conditions are based on "media features", the most common being width / min-width / max-width.
Mobile-first vs Desktop-first
Two very different writing strategies, deciding whether the default styles target the smallest or the largest screen:
Strategy
Default styles target
Media queries use
Mobile-first
Smallest screen (no query wrapper)
min-width (progressive enhancement)
Desktop-first
Largest screen (no query wrapper)
max-width (progressive degradation)
/* mobile-first: single column by default, switch to two columns on wide screens */.grid { grid-template-columns: 1fr; }
@media (min-width: 768px) {
.grid { grid-template-columns: 1fr 1fr; }
}
RecommendationMobile-first is today's mainstream practice: the default styles are the simplest and cover the widest range of devices, and you then progressively "enhance" toward large-screen layouts with min-width. It carries less cognitive load and fits the philosophy of progressive enhancement.
How to Choose Breakpoints
Rather than memorizing a pixel value, remember one principle: breakpoints should be determined by content, not by device model — when your layout starts to "look wrong" at some width (lines of text too long, cards squeezed too narrow), that is where a breakpoint belongs. The following are common reference ranges to start with:
Range
Typical devices
Common values
Extra-small
Phones in portrait
< 480px
Small
Phones in landscape / small tablets
≥ 480px
Medium
Tablets
≥ 768px
Large
Laptops
≥ 1024px
Extra-large
Desktop monitors
≥ 1280px
Combining Multiple Conditions
Use and to connect several features for "all must hold"; separate groups of queries with commas for "any may hold" (a logical OR).
/* width between 600px and 900px, and landscape */@media (min-width: 600px) and (max-width: 900px) and (orientation: landscape) {
...
}
/* phones or print scenarios */@media (max-width: 480px), print {
...
}
Modern CSS also supports range syntax, equivalent to the above but closer to math notation: @media (600px <= width <= 900px).