A
B
C
Stacked blocks on narrow screens.
If you searched for css media queries or responsive breakpoints, you usually need a mobile-first base stylesheet plus min-width rules that add layout at tablet and desktop sizes. This tutorial shows breakpoint patterns, prefers-reduced-motion, and how media queries pair with flexbox and grid.
Default CSS targets phones. Wider layouts are added with min-width media queries.
Stacked blocks on narrow screens.
At min-width 40rem, the grid becomes two columns.
/* Mobile-first */
.layout { display: flex; flex-direction: column; gap: 1rem; }
@media (min-width: 40rem) {
.layout {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
}Use rem-based breakpoints so they respect user font settings.
Comfortable reading width on tablets.
More whitespace on large screens.
@media (min-width: 48rem) { .container { padding-inline: 2rem; } }
@media (min-width: 64rem) { .container { max-width: 72rem; margin-inline: auto; } }Respect user OS settings for motion and color theme.
Animation only runs when the user allows motion.
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}