How Responsive Breakpoints Actually Work (With a Live Demo)
One column on your phone, four on your desktop. Here's how CSS Grid and a few media queries make the switch, and the one rule about order that trips everyone up.
Told by Vishwa, with Kai asking the questions
Vishwa: Drag the edge of your browser window, Kai. Watch what the layout does, and watch what you say.
↔ Drag the window edge. That's the whole pitch.
The one-sentence version
A breakpoint is the width at which your CSS swaps one layout rule for another. Below 640px: one column. At 640px or wider: two. That's the whole idea; everything else is detail.Kai's first attempt
KaiEasy. I'll look up the iPhone width, the iPad width and the laptop width, and write a rule for each device.
/* one rule per device… */
@media (max-width: 1024px) {
.cards {
grid-template-columns: repeat(3, 1fr);
}
}
/* iPad */
@media (max-width: 768px) {
.cards {
grid-template-columns: repeat(2, 1fr);
}
}
/* iPad mini */
@media (max-width: 430px) {
.cards {
grid-template-columns: 1fr;
}
}VishwaYou built the walls around the furniture, Kai. Build them around what lives inside: the cards.
The setup: CSS Grid does the heavy lifting
Start mobile-first. The base rule is the smallest layout, so phones need no media query at all:/* Base: one column. No media query needed. */
.cards {
display: grid;
grid-template-columns: repeat(1, 1fr);
gap: 12px;
}Adding breakpoints
Each wider layout is layered on with a min-width query: "from this width upwards, do this instead"./* Tablet: 2 columns */
@media (min-width: 640px) {
.cards {
grid-template-columns: repeat(2, 1fr);
gap: 14px;
}
} /* Laptop: 3 columns */
@media (min-width: 900px) {
.cards {
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}
} /* Desktop: 4 columns */
@media (min-width: 1180px) {
.cards {
grid-template-columns: repeat(4, 1fr);
gap: 18px;
}
}The part that confuses everyone
KaiWait. At 1200px, the 640, 900 and 1180 rules all match. Which one wins?
min-width, breakpoints must go from smallest to largest; the widest matching rule comes last and takes over.
Put the 640px rule at the bottom by mistake and every screen above 640px gets two columns, no matter how wide it is. No error, no warning. Just a layout that stops growing.
Why 1fr makes this painless
- No percentage maths.
repeat(3, 1fr)means three equal shares of the free space. No33.333%, no rounding gaps. - Fluid between breakpoints. Cards stretch and shrink smoothly; the breakpoint only changes how many fit in a row.
- Gaps are real spacing.
gapsits only between cards, so there's no margin on the last item to cancel out. - One-line changes. Five columns instead of four? Change one number.
Bonus: a grid with no breakpoints at all
If all you need is "as many cards as fit, each at least 240px wide", Grid can work out the column count by itself:.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 16px;
}A gotcha I hit while building the demo
The live demo resizes a frame, not your whole browser, so it uses container queries instead of media queries. Container queries measure the container's content box: its width minus padding and borders..frame {
container-type: inline-size;
padding: 16px; /* this padding is subtracted from what the query sees */
}
@container (min-width: 1180px) {
.cards {
grid-template-columns: repeat(4, 1fr);
}
}KaiSo breakpoints come from my content, go smallest to largest, and the box I measure matters. Got it!
Takeaways
- Write mobile-first. The base rule is the smallest layout;
min-widthqueries add the rest. - Choose breakpoints from content, not device lists. Widen until the layout looks wrong, then add one.
- Use Grid with 1fr and let breakpoints change more than columns: gap, padding and type too.
- Remember the cascade. Same specificity means the last matching rule wins, so order breakpoints smallest to largest.
Try it yourself: open the interactive breakpoints demo, drag the handle, and watch each rule take over.Acharya's RuleLet the content choose the breakpoint, not the device. Start small, add rules as the room grows, and keep them in order.
Frequently asked questions
What is a responsive breakpoint?
A breakpoint is the width at which your CSS switches from one layout rule to another, for example from one column below 640px to two columns at 640px and wider.
Should I use min-width or max-width media queries?
For mobile-first CSS, use min-width. The base styles are for the smallest screens, and each min-width query adds the layout for wider screens. Keep them ordered from smallest to largest.
Which breakpoints should I use?
Choose them from your content rather than device widths. Widen the layout until it starts to look cramped or stretched, and add a breakpoint there. Common starting points are around 640px, 900px and 1180px.
Can CSS Grid be responsive without media queries?
Yes. grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) fits as many columns as there is room for, each at least 240px wide. Use media queries when other things need to change too, such as gap, padding or font size.