Sub topic 7
Choosing breakpoints from the content, not from devices
This chapter assumes you can write media queries and mobile-first CSS with min-width, and that you know the mobile, tablet, and desktop frame setup from the previous chapters. It also assumes you are comfortable with rem and em units.
Why device lists fail
A common first approach is to list popular devices and give each one a breakpoint, such as 375px for one phone and 768px for one tablet. The list goes stale as new devices ship. Windows also resize, phones rotate, and browsers can be zoomed, so the width your CSS sees is often not a width on your list.
A breakpoint should answer one question: at what width does this layout stop working? You find that width by looking at the content.
Find the break by resizing
Start with the single-column mobile layout and widen the browser slowly. Watch for the first sign of trouble. Common signs are:
- Lines of text become longer than about 75 characters, which is hard to read.
- Gaps between elements grow so large that the page looks empty.
- A card, image, or form field stretches far beyond a useful size.
- There is room for a second column that would fit the content well.
Write down the width where the first problem appears. Add a media query there, fix the problem, and keep widening until the next one appears.
Use em or rem for breakpoint widths
Express breakpoints in em or rem, not px. In media queries these units are relative to the browser's default font size, not to your CSS. When a user raises their text size, an em breakpoint moves to a wider screen width, so the layout changes sooner and the text keeps room to breathe. A px breakpoint ignores that setting.
/* 48em = 768px at the default 16px font size */
@media (min-width: 48em) {
.layout {
grid-template-columns: 1fr 1fr;
}
}Let fluid layout reduce the count
Fluid techniques remove many breakpoints before you write them. This grid changes its column count as its container width changes, and needs no media query.
.cards {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}Use a breakpoint only when the layout needs a structural change that fluid rules cannot make, such as moving from one column to a sidebar plus main area.
Keep the set small and name it
Most sites need only two or three breakpoints. Fewer breakpoints mean fewer states to design, build, and test. Record each one as a design token so designers and developers use the same values.
| Token | Value | Typical change |
|---|---|---|
| `bp-md` | 48em | Single column becomes two columns |
| `bp-lg` | 80em | Adds a third column and caps the width |
Name tokens by size, not by device. A name like bp-ipad becomes wrong the day the device changes.
Connect the tokens to your frames
Your frames are examples of the layout at chosen widths. Build the mobile, tablet, and desktop frames so each one sits inside a breakpoint range, not on its edge. Make the tablet frame wider than bp-md and the desktop frame wider than bp-lg. A frame that sits exactly on a breakpoint hides the behavior just below it.
Common errors
- Choosing breakpoints from a device list and never checking the content.
- Adding a breakpoint for every small flaw when a fluid rule would fix it.
- Mixing
pxandembreakpoints in one stylesheet, which makes ranges overlap or leave gaps. - Using different values in the design file and in the code.
Exercise
A card grid looks fine at 360px and 700px. At 900px the text lines in a single column are about 110 characters long. What do you do, and which unit do you use for the width?
Show answer
Widen the window to find the width where lines first become too long, and add a min-width media query at that width, for example 48em, that changes the layout to two columns. Use em or rem so the breakpoint follows the user's text size setting. Then record the value as a design token and check the frames match.