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 do not need a design tool yet, but later chapters map these ideas onto frames in tools such as Figma.
What a breakpoint is
A breakpoint is a viewport width at which your layout changes on purpose. Below the width you get one arrangement. At or above it, you get another. In CSS, a breakpoint is usually the number inside a media query, such as 48em.
The word "break" can mislead you. The layout does not fail at that width. You are choosing to switch from one design to another.
Why one layout is not enough
A layout that works at 360 CSS pixels wide has problems at 1400. Lines of text grow too long to read comfortably. Single-column content leaves large empty margins. A layout built for 1400 has the opposite problem on a phone. Columns get too narrow, text wraps after a few words, and users scroll sideways.
Fluid techniques such as percentages, fr units, and max-width stretch and shrink a layout, but only up to a point. A three-column grid can shrink until each column is unreadable. At that point the structure has to change, for example from three columns to one. That change is what a breakpoint does.
Two kinds of change
It helps to separate two ideas:
- Fluid change happens continuously. The layout adjusts a little with every pixel of width.
- Structural change happens at a breakpoint. Columns appear, navigation turns into a menu, or the order of sections changes.
A good responsive layout uses fluid change for most of the range and adds breakpoints only where fluid change stops working.
A first breakpoint in code
This stylesheet has one breakpoint. Below 48em the grid has one column, because that is the default. At 48em and above it has two.
.layout {
display: grid;
gap: 1rem;
padding: 1rem;
}
/* Tablet and up */
@media (min-width: 48em) {
.layout {
grid-template-columns: 1fr 1fr;
}
}Between 0 and 48em the layout is fluid: the single column fills the width. Between 48em and wider screens it is fluid again, with two equal columns that grow with the viewport. The only structural change is at 48em.
Breakpoints and design frames
Designers draw a layout at specific widths, usually as separate frames named mobile, tablet, and desktop. Each frame is a snapshot of the layout inside one range. The breakpoints are the boundaries between those ranges.
| Concept | Where it lives | What it describes |
|---|---|---|
| Frame | Design tool | One example width, such as 390 or 1440 |
| Breakpoint | CSS | The width where the layout changes |
| Range | Both | All widths between two breakpoints |
A frame is not a breakpoint. A mobile frame at 390 pixels does not mean your CSS changes at 390. It means the design shows how the layout looks somewhere in the mobile range.
Common mistakes
- Treating breakpoints as device sizes. Phones and tablets come in many widths, and new ones appear every year. Pick breakpoints where your content needs them.
- Adding too many breakpoints. Each one is another layout to test and maintain. Start with fluid CSS and add a breakpoint only when something looks wrong.
- Forgetting the viewport meta tag. Without it, mobile browsers use a wide virtual viewport, and your media queries match the wrong width.
- Checking only at the frame widths. A layout can look fine at 390 and 1440 and break at 700. Later chapters cover testing between breakpoints.
Summary
A breakpoint is a width where the layout's structure changes. Fluid layout handles small differences in width, and breakpoints handle changes that fluid layout cannot. Design frames show the layout inside each range, and CSS breakpoints mark the edges between the ranges.
Exercise
A three-column grid uses 1fr columns and looks fine at 1200px. At 700px the columns are too narrow to read. Is this a case for a fluid change or a breakpoint, and what would you change at the breakpoint?
Show answer
It needs a breakpoint. Fluid sizing already shrinks the columns, and they have become too narrow, so the structure must change. Add a media query at roughly the width where the columns become cramped, and switch to two columns (or one) below it. In mobile-first CSS you would define the one-column layout by default and add columns with min-width queries.
Exercise
Your design file has a mobile frame at 390px and a desktop frame at 1440px. A teammate writes @media (min-width: 390px) to match the mobile frame. What is wrong with this approach?
Show answer
A frame is a sample width, not a breakpoint. The layout does not need to change at 390px, and the query would also be true for every wider screen. Choose the breakpoint from the width where the content stops working, then show the layout on each side of it in the frames.