You designed the page on a wide monitor: three columns, a sidebar beside the article, a row of product cards. Then you open it on a phone and the same columns are still there, squeezed into a fraction of the width. Text runs in thin ribbons, links sit on top of each other, and the layout works yet is miserable to use.
The fix is not a smaller version of the same layout. It is a different layout below a chosen width: one column, full width, everything in a single scroll. This guide shows how to build that media query with the free Media Query Builder on Ovatly, and how to write the stacking rules that go inside it.
Contents
- Quick answer
- Why stacking beats shrinking
- The query decides when, your CSS decides what
- Choosing the width where stacking starts
- How to build the stacking query, step by step
- Worked example: a three-column section that stacks at 767px
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Stacking takes two pieces. First, a media query block that applies only below the width where your columns stop working, for example @media screen and (max-width: 767px). Second, your own CSS inside that block that turns the columns into a single column, typically by switching a flex row to a column and giving each item full width. The Media Query Builder assembles the first piece: set the media type, enter a max width, and copy the block it produces, placeholder comment included. The stacking rules themselves are always yours to write, in place of that placeholder.
Why stacking beats shrinking
A browser will happily shrink a three-column layout to fit a 380px screen. Nothing breaks, and that is the problem: the failure is quiet. Columns that were 400px wide become 120px wide, and a paragraph turns into a tall stack of two-word lines.
Tap targets suffer the same way. Links and buttons designed for a mouse pointer end up a few pixels apart, and a thumb covers several at once. People navigate by tapping, not hovering, so targets need to stay roughly fingertip-sized.
Stacking avoids both failures by changing the arrangement instead of the scale. Each column gets the full width of the screen in turn, so text keeps a comfortable line length and interactive elements stay finger-sized. The content order becomes the reading order once they stack.
The query decides when, your CSS decides what
A media query is a condition wrapped around ordinary CSS. The block applies only when the condition is true, in this case when the viewport is at most 767 CSS pixels wide. Everything between the braces is plain CSS that you write.
The Media Query Builder builds the wrapper. You choose a media type, screen or all, set min and max widths or heights in pixels, and optionally add an orientation condition. The builder combines conditions with and, checks for obvious errors such as a minimum larger than the maximum, and outputs a complete @media block with a placeholder comment inside.
What the builder does not do is stack anything. The placeholder comment marks the exact spot where your stacking rules belong, and writing them is the second half of the job.
Choosing the width where stacking starts
The builder offers presets based on common device sizes. Be clear about what they are: widely used conventions, not official standards. No standards body declares that phones end at 767px.
The better method is to find the width where your own layout stops working. Narrow a browser window slowly and watch the columns: at some point the text gets cramped or the sidebar starts elbowing the article. That width is your stacking point, and the builder accepts exact pixel values, so the max width can be the number your layout actually needs.
One technical point matters here: widths in media queries are CSS pixels, not the physical pixels of the screen. A phone with a very sharp display still reports a viewport a few hundred CSS pixels wide, which is why one query covers many devices.
How to build the stacking query, step by step
- Open the Media Query Builder.
- Choose the media type: screen for almost every stacking query.
- Leave the minimum width empty (no lower limit) and set the maximum width to your stacking point, for example 767.
- Leave orientation unset unless you only want the stacked layout in one orientation.
- Copy the generated block into your stylesheet, after the rules it needs to override.
- Replace the placeholder comment inside the block with your stacking rules.
Order in the stylesheet matters: the block has to come after the base column rules, because when both apply, the later rule of equal specificity wins.
Worked example: a three-column section that stacks at 767px
Say a page section shows three columns side by side: an intro, a feature list and a signup box. On a phone, all three need to stack. In the builder, set media type to screen, max width to 767, and everything else empty. It produces exactly this:
@media screen and (max-width: 767px) {
/* your CSS here */
}
On its own, that block changes nothing. Now replace the placeholder comment with your stacking rules. If the columns use flexbox, the generic pattern looks like this:
@media screen and (max-width: 767px) {
.columns {
flex-direction: column;
}
.column {
width: 100%;
}
}
The first rule turns the horizontal row into a vertical one; the second gives each column the full width instead of its desktop share. Class names and the layout system are yours; a grid layout would use its own equivalent. What the builder contributed is the condition, correct and checked. What you contributed is the stacking itself.
Limitations and honest tradeoffs
The builder assembles query blocks; it does not analyze your layout, suggest breakpoints from your code, or write layout CSS. Its presets are conventions, and they can disagree with what your analytics say about your actual visitors. Treat them as a starting grid, not an answer.
Stacking has costs too. A stacked page is a long page: readers scroll further, and content that sat side by side for comparison, such as pricing tiers, loses that at-a-glance quality. Stacking is the right default for text-heavy columns, not a law for every component.
Finally, the query responds to viewport width, not device type. A narrow desktop window stacks too, which is normally what you want, but surprises people who test by resizing.
Common mistakes
- Setting a minimum width instead of a maximum. A min-width block applies above that width, so the stacked layout lands on desktops and phones keep the squeezed columns.
- Placing the block before the base rules. Later rules win ties, so a media query written above the layout it overrides may silently do nothing.
- Copying a preset without checking your layout. 767px is a convention. If your columns break at 900px, a 767px query leaves a band of broken widths in between.
- Stacking but keeping desktop spacing. Desktop gaps and margins, stacked vertically, turn into long empty stretches. Adjust spacing inside the same block.
- Leaving the max width empty. An empty field means no limit, so the block applies at every width, not just on small screens.
FAQs
Does the Media Query Builder write the stacking CSS for me? No. The builder assembles the @media block with a placeholder comment inside. The rules that stack your columns, such as switching a flex row to a column at full width, are your CSS, written in place of that placeholder.
What breakpoint should I use for stacking? There is no official number. 767px is a widely used convention for the top of the phone range, but the right width is the one where your columns become too narrow to read. The builder accepts exact pixel values, so you can match your layout instead of a preset.
Why not just let the columns shrink on small screens? Shrunken columns keep the layout but ruin the content: lines of text become a few words wide and links sit too close together to tap accurately. Stacking gives every column the full width, so type size and tap targets stay usable.
Do I need a separate query for tablets? Only if the layout needs an in-between state, such as two columns instead of three. Add a second block with a min and max width so it applies only in that range; an empty field in the builder means no limit on that side.
Does this tool upload my stylesheet anywhere? No. The builder runs entirely in your browser and works locally. You copy the finished block into your own stylesheet yourself.
Conclusion
Stacking is a division of labor: the media query picks the moment, your CSS does the work. Generate the block with the Media Query Builder, paste it after your base layout rules, and write the one-column version of your design inside it. If your layout also misbehaves when a phone rotates, our guide to orientation queries for landscape phones covers the other condition the builder offers. For more guides in this series, see our Website and Webmaster Tools guides, which pair each technique with the free tool that performs it.
References
- MDN Web Docs, on using media queries and responsive design: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries
- web.dev (Google), on responsive design basics and layout patterns: https://web.dev/articles/responsive-web-design-basics