Sub topic 6
Choosing breakpoints from the content, not from devices
This chapter assumes you can write a min-width media query, you have a single-column base layout with the viewport meta tag in place, and you can use your browser's responsive mode in developer tools.
Why device-based breakpoints age badly
A breakpoint is a viewport width at which your CSS changes. A common habit is to copy widths from a list of devices, such as 375px for a phone and 768px for a tablet. That list is out of date within a year. It also ignores browser windows that users resize, split-screen modes, foldable phones, and page zoom, all of which produce widths that match no device.
A content-driven breakpoint is different. You add it at the width where your own layout starts to look wrong. The layout, not the hardware, tells you where to change it.
Finding a breakpoint by stretching
Because the base layout is mobile-first, you start narrow and work upward:
- Open the page in responsive mode at about 320 CSS pixels wide.
- Drag the width handle slowly to the right.
- Stop when something looks wrong. Typical signs are lines of text far too long, large empty gaps, or cards that could sit side by side.
- Note the width and add a min-width query there.
- Keep dragging and repeat.
A worked example
Suppose each card needs about 18em of width to read comfortably. Two columns therefore need roughly 2 × 18em plus a 1em gap and 2em of page padding, which is about 39em. We round up to 40em. Three columns need 3 × 18em plus two gaps and the padding, about 58em. We round up to 64em, which leaves room for a scroll bar.
.card-list {
display: grid;
gap: 1rem;
padding: 1rem;
}
/* Two cards of about 18em each fit from roughly 39em. */
@media (min-width: 40em) {
.card-list {
grid-template-columns: repeat(2, 1fr);
}
}
/* Three cards fit from roughly 58em, rounded up for a scroll bar. */
@media (min-width: 64em) {
.card-list {
grid-template-columns: repeat(3, 1fr);
}
}The numbers come from the card content. If you later make the cards narrower, you move the breakpoints, and no device list is involved.
Use em in the query, not px
Write breakpoints in em. In a media query, 1em equals the browser's default font size, usually 16px, regardless of your own CSS. When a user raises their default text size or zooms in, an em query fires at a wider pixel width. This switches to the simpler layout when the larger text no longer fits the multi-column one. A px query ignores that setting.
Sometimes you need no breakpoint
If the only change is "more columns when there is room", a grid can do it without any query:
.card-list {
display: grid;
gap: 1rem;
padding: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(18em, 100%), 1fr));
}The browser fits as many 18em columns as the width allows. The min(18em, 100%) stops a column from overflowing a very narrow screen. Use explicit breakpoints when the layout changes shape, for example when a sidebar appears or navigation changes. Let the grid handle simple column counts.
Common errors
| Mistake | Why it hurts | Fix |
|---|---|---|
| Breakpoints copied from a device list | They match hardware that changes and miss every other width | Find them by dragging the width |
| Testing only at preset device sizes | The layout can break between the presets | Drag the handle across the full range |
| `max-width` queries layered over a desktop layout | This is desktop-first, and it makes small screens undo styles | Write the base for small screens and add `min-width` queries |
| Breakpoints in `px` | They ignore the user's text size setting | Use `em` |
| A new breakpoint for every small flaw | Each one adds CSS you must maintain | Fix small flaws with fluid sizing first, and expect only a few breakpoints |
Exercise
Your single-column article page has body text that becomes about 110 characters per line at 50em, which is hard to read. A teammate suggests adding a query at 768px because "that is the tablet width". Give two reasons this is the wrong approach and describe a better one.
Show answer
First, 768px is a device width, not the width where your content breaks, which is about 50em in this page. Second, a px query ignores the user's text size setting, so it fires at the wrong point for users who enlarge text. A better approach is to widen the viewport in responsive mode, see where lines get too long, and fix it there. Setting max-width: 65ch on the text container may remove the need for a query. If a layout change is needed, such as a sidebar, add a min-width query in em at the width where it breaks.