Sub topic 2
What a Breakpoint Is and Why Layouts Need Them
This chapter assumes you know basic HTML and CSS, including the box model and selectors. It also assumes you are comfortable with px, rem, and percentage units. You should also have seen a design tool that uses frames, such as Figma. Media query syntax gets its own chapter later, so here we focus on the idea of a breakpoint and the problem it solves.
The problem: one layout cannot fit every width
A page is shown on screens that range from about 320 CSS pixels wide (a small phone) to 2500 or more (a large monitor). A layout that works well at one width tends to fail at the others.
Consider a three-column layout with a sidebar, a main area, and a second sidebar. On a wide monitor it looks balanced. On a phone, each column becomes too narrow to read. Lines of text hold only two or three words, and buttons squeeze together. The reverse also fails. A single-column phone layout stretched across a large monitor produces lines of text 200 characters long, which are hard to read, and large empty areas on both sides.
You have two ways to handle this. You can let the layout flex continuously, so columns and text grow or shrink with the available width. You can also change the structure of the layout at certain widths. Real pages need both. The second tool is the breakpoint.
Definition
A breakpoint is a viewport width at which the layout changes its rules. Below the breakpoint, one set of CSS applies. At or above it, a different set applies. The usual change is structural: a single column becomes two columns, a menu collapses into a button, or an image moves from above the text to beside it.
In CSS, a breakpoint is written as a media query condition:
/* Applies at every width */
.layout {
display: grid;
gap: 1rem;
}
/* Applies only when the viewport is at least 48em wide */
@media (min-width: 48em) {
.layout {
grid-template-columns: 1fr 1fr;
}
}The value 48em is the breakpoint. The browser compares the current viewport width to it, and the second rule block switches on or off. Nothing happens gradually. The change occurs at exactly one width.
The word "breakpoint" is used in two senses, and the difference matters throughout this tutorial:
- In design, a breakpoint is a planned width where you expect the layout to change. You express it as a frame width in a design tool.
- In code, a breakpoint is the actual value in a media query.
The two should match. Much of the work in this tutorial is keeping them aligned.
Fluid change and stepped change
A layout responds to width in two different ways. It helps to keep them apart.
- Fluid change happens continuously. A column set to
width: 50%is 160px wide in a 320px container and 600px wide in a 1200px container. No query is involved, and there is no jump. - Stepped change happens at a breakpoint. The layout holds its structure over a range of widths, then switches to a different structure at a threshold.
The diagram shows how the two combine. Between breakpoints, the layout stretches fluidly. At each breakpoint, it changes structure.
A well-built page uses as much fluid behavior as it can and adds breakpoints only where fluid behavior is not enough. The next chapter covers fluid layouts in detail. For now, remember that each breakpoint adds code you must maintain and test, so fewer is better.
Why layouts need stepped change
Fluid rules cannot do everything. Four common situations call for a breakpoint.
- A column count would fall below a usable size. Two columns of 150px each read poorly. At some width it is better to switch to one column.
- Text line length leaves the readable range. Body text is comfortable at roughly 45 to 75 characters per line. A fluid single column on a wide screen exceeds that, so you add columns or cap the width.
- A component needs a different form. A horizontal list of ten navigation links fits on a desktop. On a phone it does not, so it becomes a menu button that opens a panel. No amount of shrinking turns a row of links into a button.
- The relationship between elements changes. An image next to a heading works in a wide area. In a narrow one, it should sit above the heading. Order and arrangement are structural, not proportional.
In each case, the layout reaches a width where its current structure stops working. That width is where a breakpoint belongs.
The viewport is what a breakpoint measures
A width-based breakpoint compares against the viewport, which is the visible area of the browser window for the page. It does not measure the physical screen, the device model, or the pixel count of the display. It measures CSS pixels, the layout unit covered in the previous chapter.
This is why a phone with a 1170-pixel-wide physical display can match a breakpoint at 48em. Its viewport is about 390 CSS pixels wide, so the query for min-width: 48em (768 CSS pixels at the default font size) does not match.
Two details cause confusion:
- The
emin a media query is not the font size of your elements. In media queries,emandremboth refer to the browser's initial font size, usually 16px, and not to any size you set in CSS. So48emis 768px at the default setting. If a user raises their default font size, the breakpoint in pixels rises with it. This is one reason to write breakpoints ineminstead ofpx: the layout adapts when text is larger. - The viewport meta tag must be present. Without it, mobile browsers pretend the viewport is about 980px wide and scale the page down. Your queries then compare against 980, not the real width, and the mobile layout never appears. Add this to the page head:
<meta name="viewport" content="width=device-width, initial-scale=1">Breakpoint ranges and the frames you design
Breakpoints divide the width axis into ranges. A common starting plan uses two breakpoints, which creates three ranges:
| Range | Typical width | Typical layout |
|---|---|---|
| Mobile | Below 48em (768px) | One column, stacked sections |
| Tablet | 48em to below 80em (768px to 1279px) | Two columns |
| Desktop | 80em (1280px) and up | Three columns, content capped in width |
These three ranges are the reason designers talk about mobile, tablet, and desktop frames. A frame is a design-tool artboard set to one width. You draw the layout at, say, 390, 820, and 1440 pixels wide. Each frame is one example from inside a range, not a boundary. The design tool shows what the page looks like at those three widths. The CSS decides what happens at every width in between.
Treat the names as labels for ranges of widths, not as promises about devices. A tablet in landscape orientation may report 1180 CSS pixels, which falls in the "desktop" range here. A narrow desktop browser window can fall in the "mobile" range. The layout responds to width, so the label does not matter to the browser.
A worked example
Take a simple article page with a header, an article, a related-links box, and a footer. Plan the behavior in words before writing code.
- Narrow: everything stacks in one column, in the order header, article, related links, footer.
- Medium: the related-links box moves beside the article, in a second column.
- Wide: the layout is capped at a maximum width and centered, so lines stay readable.
The code that matches this plan:
.page {
display: grid;
gap: 1rem;
padding: 1rem;
}
/* Medium: add a second column */
@media (min-width: 48em) {
.page {
grid-template-columns: 2fr 1fr;
}
.page > header,
.page > footer {
grid-column: 1 / -1;
}
}
/* Wide: cap and center the layout */
@media (min-width: 80em) {
.page {
max-width: 80rem;
margin-inline: auto;
}
}The base rules, outside any query, describe the narrow layout. Each query adds only what changes. The header and footer span both columns using grid-column: 1 / -1, which means "from the first line to the last line."
Notice what is fluid here. Inside each range, 2fr 1fr and the percentage-like behavior of grid keep the columns proportional as the width changes. The breakpoints only decide how many columns exist.
Common errors
- Choosing breakpoints from a device list. Picking 375, 768, and 1024 because they match specific phones and tablets ties your layout to hardware that changes every year. Choose widths where the content breaks instead. A later chapter covers how.
- Adding too many breakpoints. Every breakpoint multiplies the combinations to test. If one fluid rule can replace a breakpoint, use it.
- Forgetting the viewport meta tag. The page looks like a shrunken desktop site on phones, and your mobile styles never apply.
- Using different values in design and code. If the frames assume 768px and the CSS uses 800px, the page will not match the design between those widths. Keep one agreed list of values.
- Leaving gaps or overlaps between ranges. Mixing
max-widthandmin-widthwith the same number matches the exact boundary width in both ranges. A later chapter on mobile-first CSS shows a way to avoid this. - Treating the frame width as the only width that matters. A layout drawn at 820px must also work at 780px and 1000px. Breakpoints are thresholds, and the space between them must hold up too.
Summary
A breakpoint is a viewport width where the layout's rules change. Fluid rules handle continuous change, and breakpoints handle the structural changes that fluid rules cannot, such as column counts, component forms, and element order. Breakpoints split the width range into bands, and mobile, tablet, and desktop frames are sample widths from those bands. The viewport meta tag makes the widths your queries see match the real screen. Keep the number of breakpoints small and the design and code values identical.
Exercise
A page has a media query @media (min-width: 48em) and the viewport meta tag is missing. A phone with a 1080-pixel-wide physical display loads the page. Will the two-column layout inside the query apply? Explain, and say what single line you would add to fix it.
Show answer
Yes, the two-column layout will probably apply, which is the wrong result. Without the viewport meta tag, a mobile browser lays the page out in a virtual viewport about 980 CSS pixels wide. That is larger than 768px (48em at the default 16px), so the query matches and the phone shows the tablet layout, scaled down. Add <meta name="viewport" content="width=device-width, initial-scale=1"> to the head. The viewport then equals the device width in CSS pixels (about 360 to 430 for most phones), and the query no longer matches.
Exercise
A designer draws frames at 390, 820, and 1440 pixels wide. A developer writes breakpoints at 768px and 1280px. Do the frames and the code match? What might go wrong between 768px and 820px, and how would you fix the mismatch?
Show answer
Each frame falls inside a range that the code defines (390 is below 768, 820 is between 768 and 1280, and 1440 is above 1280), so each frame matches one layout. The ranges themselves are not recorded in the design, though. The designer may have assumed the tablet layout starts at 820, not 768. Between 768 and 820, the page would show the tablet layout at widths nobody has designed or reviewed, and it might look cramped. To fix it, agree on one list of breakpoint values, such as 768 and 1280, and add a check at the lower edge (768) and just above it. The designer can also add frames at those edges.
Exercise
Name one change that needs a breakpoint and one that does not. For each, give a reason.
Show answer
A row of ten navigation links that must become a menu button on narrow screens needs a breakpoint, because the component changes form and no scaling rule can turn links into a button. Slightly increasing the page padding as the screen gets wider does not need one, because a fluid rule such as a percentage or clamp() changes the value continuously without adding a new range to maintain.