Sub topic 6
Choosing breakpoints from the content, not from devices
This chapter assumes you can write basic HTML and CSS, know the box model and units such as em and rem, and have already built a single-column base layout with min-width media queries. If any of that is unfamiliar, review the earlier chapters on the fluid layout and on min-width queries first.
What a breakpoint is
A breakpoint is a viewport width at which your CSS changes the layout. In a mobile-first stylesheet, each breakpoint is a min-width media query. The rules inside it apply from that width upward.
The question for this chapter is where to put those widths. There are two common answers:
- Device-driven: pick widths that match popular devices, such as a phone, a tablet and a laptop.
- Content-driven: start narrow, widen the viewport, and add a breakpoint at the width where the content starts to look wrong.
The mobile-first approach favours the second answer. This chapter explains why and shows how to find those widths in practice.
Why device-based breakpoints fail
Device sizes are a moving target. New phones, foldable screens, tablets in split view, resizable desktop windows and browser zoom all produce widths that no list of devices predicts. A stylesheet tuned to last year's phone widths will still work on this year's, but only by luck.
Device-based breakpoints cause three recurring problems:
- Gaps between the chosen widths. A layout built for 375px and 768px says nothing about 600px. If the design looks cramped or stretched there, nobody notices until a user hits it.
- Unnecessary rules. A breakpoint placed at a device width may change nothing visible. It still adds CSS to maintain.
- A false sense of coverage. Passing a check on three devices does not show that the layout works at every width between them.
A page is viewed in a continuous range of widths. A good breakpoint is a response to the content, so it keeps working whatever device the reader holds.
The content-driven method
The method is short: begin with the base layout, widen the viewport slowly, and watch for the first width at which the design stops serving the content. Add a breakpoint there. Then keep widening.
Step by step
- Build the single-column base styles with no media queries.
- Open the page in your browser's developer tools and enter responsive design mode, so you can drag the viewport edge.
- Start at a narrow width, such as 320px, and confirm the base layout reads well.
- Drag the edge wider, slowly.
- Stop when something looks wrong. Typical signs are given below.
- Note the width, choose a round value near it, and add a
min-widthquery that fixes the problem. - Continue widening and repeat from step 5.
Signs that a breakpoint is needed
- Lines of text grow far beyond a comfortable length. A common guide is roughly 45 to 75 characters per line.
- Large empty areas appear beside a single column.
- Images stretch much larger than their useful size.
- A row of items could fit side by side but is still stacked.
- A multi-column arrangement, once added, begins to squeeze its columns until they are too narrow to read.
Each sign points to a specific change. Long lines suggest limiting the width of the text block or adding a second column. Wasted space suggests a grid. Stacked items that fit suggest placing them in a row.
Worked example: a card list
The card list from the earlier chapter uses two breakpoints. Here is the same code, shown again so the numbers can be examined.
.card-list {
display: grid;
gap: 1rem;
padding: 1rem;
}
@media (min-width: 40em) {
.card-list {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 64em) {
.card-list {
grid-template-columns: repeat(3, 1fr);
}
}The values 40em and 64em were not taken from any device. They come from how wide a card needs to be. Suppose a card holds a title, a short paragraph and a button, and it stays readable down to about 18em wide. Then:
- Two columns need roughly 2 × 18em plus the gap and padding, which is a little under 40em.
- Three columns need roughly 3 × 18em plus gaps and padding, which is a little under 64em.
So each breakpoint marks the width at which the next column fits. If you later make the cards narrower or wider, you would move the breakpoints. A device list would not tell you that.
Use em, not px, in media queries
The example above writes breakpoints in em. In media queries, em and rem both refer to the browser's default font size, not to any font size set in your CSS. This means a query written as 40em is 640px for a user with the default 16px setting and 800px for a user who has raised the default to 20px.
That behaviour is useful. A user who enlarges their text needs fewer characters per line to be comfortable, so the layout should switch to multiple columns later. With pixel breakpoints, the layout would switch at the same viewport width and squeeze larger text into narrow columns. With em breakpoints, the switch moves with the text size.
| Unit in the query | Responds to the user's default font size | Notes |
|---|---|---|
| `px` | No | Fixed viewport width, regardless of text size |
| `em` | Yes | Based on the browser default, not on your CSS |
| `rem` | Yes | Also based on the browser default in media queries |
Pick one unit and use it consistently, so that queries are easy to compare.
Prefer a few breakpoints
Content-driven design tends to produce few breakpoints, often two to four for a whole site. Resist the urge to add more. Each one multiplies the number of layouts you must test.
Before adding a breakpoint, try a technique that adapts without one. Many layouts can respond smoothly using flexible tools:
.card-list {
display: grid;
gap: 1rem;
padding: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18em), 1fr));
}Here the grid places as many columns of at least 18em as fit, and the browser decides the count at every width. No media query is needed. The min(100%, 18em) part stops a column from overflowing a very narrow container.
This does not make media queries obsolete. Use a breakpoint when the layout must change in structure, for example when a navigation bar changes from a toggled menu to a visible row of links, or when a sidebar appears beside the main content. Use intrinsic techniques such as auto-fit when you only need the number of columns to vary.
Naming and organising breakpoints
Because breakpoints come from the content, they are often specific to a component. A navigation bar may need a breakpoint at 48em, while a gallery needs one at 36em. This is acceptable. Keep the query next to the component it affects, and keep the rules inside it small.
If you want shared values, define them once. Custom properties cannot be used inside a media query condition, so shared values are usually kept in a comment, a design token file, or a preprocessor variable. A simple convention is a comment block at the top of the stylesheet:
/*
Breakpoints used in this stylesheet:
40em - second column fits (cards, gallery)
48em - navigation links fit in one row
64em - third column fits; sidebar appears
*/Describe each value by the content change it causes. A note such as "navigation links fit in one row" tells the next developer why the number exists. A label such as "tablet" does not.
Common mistakes
- Choosing widths first. Writing
@media (min-width: 768px)out of habit, before checking whether the layout needs it at that width. - Using
max-widthqueries to undo base styles. This reverses the mobile-first order and makes the stylesheet harder to follow. Keep base styles for the small screen and add withmin-width. - Testing only at the breakpoint. A layout can look right exactly at 40em and wrong at 39.9em or 41em. Drag the viewport through the whole range.
- Forgetting the upper end. Content that works at 64em may stretch badly on a very wide monitor. Add a
max-widthto the main container so text does not spread across the screen. - Mixing units. Combining
pxandemqueries in one file makes the order of rules hard to reason about.
A decision flow
The following diagram summarises how to decide whether a given width needs a breakpoint.
Checking your result
After you have placed the breakpoints, check the layout at several points:
- Just below each breakpoint and just above it.
- At the narrowest width you support.
- At a very wide width, such as a large external monitor.
- With the browser's default text size increased.
If you find a problem between two breakpoints, you have found a missing one, or a base style that needs a more flexible rule.
Summary of the approach
Treat a breakpoint as evidence. It records a width at which the content stopped working and the change that fixed it. Placing breakpoints this way keeps the stylesheet small, makes it resilient to devices that do not exist yet, and gives every number in your CSS a reason.
Exercise
A card needs about 15em to stay readable. The grid has 1rem of padding on each side and a 1rem gap between cards. Roughly at what viewport width, in em, should you add a breakpoint for a third column? Explain why you would write the query in em rather than px.
Show answer
Three cards need 3 × 15em = 45em. Add 2em for the two gaps and 2em for the left and right padding (using 1rem as about 1em), which gives about 49em. A breakpoint near 49em (for example 50em) is reasonable. Use em because media query em units follow the user's default font size, so a user who has enlarged their text gets the third column later, when there is more room, instead of at a fixed pixel width that would squeeze larger text.
Exercise
Why is a breakpoint set at 768px "because that is a tablet" a weak choice, and what would you do instead?
Show answer
Tablet widths vary, and the same width appears on other devices and in resized desktop windows, so the number does not describe any real content need. Instead, widen the viewport in developer tools, find the width where the content first looks wrong (for example, lines too long or space wasted), and add a min-width query there.