min-width
Enhance the layout above a certain width.
Media queries apply CSS only when a condition is true. They let a design adapt to width, pointer type, motion preferences and more.
@media (min-width: 52rem) {
.layout { grid-template-columns: 18rem 1fr; }
}
@media (prefers-reduced-motion: reduce) {
* { scroll-behavior: auto; }
}
Responsive mental model
A media query asks the browser a question. If the answer is true, the rules inside it apply.
Width queries are common, but responsive CSS can also respond to hover capability, pointer precision, reduced motion and color scheme.
Good media queries are sparse and purposeful. They change the layout when the design needs a new structure, not because a specific device exists.
Enhance the layout above a certain width.
Apply a rule below a certain width when needed.
Modern readable comparisons such as width >= 48rem.
Respect reduced motion and color preferences.
Visual model
The default rules must already be usable.
A layout change starts when there is enough space.
Hover effects belong on devices that can hover.
Animation should respect user preference.
Good CSS versus fragile CSS
.layout { display: grid; gap: 1rem; }
@media (min-width: 52rem) {
.layout { grid-template-columns: 18rem 1fr; }
}
@media (prefers-reduced-motion: reduce) {
* { scroll-behavior: auto; }
}
@media (max-width: 428px) { /* iPhone */ }
@media (max-width: 390px) { /* other iPhone */ }
@media (max-width: 393px) { /* another one */ }
Rules of thumb
Write the default experience first.
Breakpoints tied to text scale often age better than hard pixel device widths.
Hover and pointer queries prevent awkward desktop-only effects on touch screens.
Reduced motion is not optional for serious production work.
Too many width queries make CSS hard to maintain.
If a query exists for a layout reason, make that reason clear.
Production thinking
Media queries let one document become many comfortable layouts. Used badly, they become a pile of device patches.
Preference queries help users who need less motion or different visual modes. Capability queries avoid hover-only interaction traps.
Audit media queries by purpose. If two queries solve the same layout pressure, consolidate them.
The same content should remain accessible across media query states. Do not create separate hidden versions of essential copy.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, resize the lab idea mentally and explain what should change.
Senior audit upgrade
Range syntax is readable, but older support requirements may still need min-width and max-width patterns.
@media (width >= 48rem) reads close to natural language.
@media (min-width: 48rem) remains widely understood and safe.
Use hover, pointer and prefers-reduced-motion queries for behavior, not just width.