Your layout looks right on the desktop monitor. Then someone opens the page on a phone and the columns stack in the wrong order, the sidebar lands on the article, or nothing changes at all and the desktop design arrives shrunk to fit. The media queries are in the stylesheet, they read correctly, and yet one never fires, or two fire at once and fight.
Media queries fail quietly: a rule that matches nothing throws no error. This guide walks through the five mistakes behind most of that failure and how to check each one, using the free Media Query Builder on Ovatly, which assembles queries from fields and validates the obvious errors before you copy anything.
Contents
- Quick answer
- What a media query actually tests
- Mistake 1: a minimum larger than the maximum
- Mistake 2: the one-pixel gap and the overlap
- Mistake 3: the missing viewport meta tag
- Mistake 4: thinking in device pixels
- Mistake 5: so many conditions that nothing matches
- How to check a query with the builder, step by step
- Worked example: the width nobody styled
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Most broken responsive layouts trace back to five query mistakes: a minimum width larger than the maximum, a one-pixel gap or overlap between ranges, a missing viewport meta tag, breakpoints chosen from physical device pixels instead of CSS pixels, and so many conditions joined with "and" that no real screen satisfies them all. Build the query in the Media Query Builder rather than from memory: it validates the range before you copy the block.
What a media query actually tests
A media query asks questions about the viewport: how wide and tall it is, whether it is taller than it is wide, and what kind of media it is, such as a screen. Conditions combine with "and", so every condition must be true at the same time for the styles inside to apply. The widths are viewport CSS pixels, not the physical pixels of the panel. And that one word, "and", is where most of the trouble starts: every condition you add narrows the set of screens that match; added carelessly, the set becomes empty.
Mistake 1: a minimum larger than the maximum
Set a minimum width of 1024px and a maximum width of 768px and you have described a viewport that cannot exist. Hand-typed CSS accepts this, because an empty range is valid syntax; the styles inside are simply dead.
The check is to read the two numbers side by side. This is the one mistake a builder removes entirely: the Media Query Builder validates the fields and flags a minimum above the maximum, instead of handing you a block that can never fire.
Mistake 2: the one-pixel gap, and its twin the overlap
Breakpoints usually come in neighbouring pairs: small screens up to some width, larger screens from there on. If the first range ends at a max-width of 767px and the next begins at a min-width of 769px, a viewport exactly 768px wide matches neither and gets the base styles and nothing else.
The twin mistake is the overlap: ranges that both cover the same width apply two rule sets at once, and source order, not your intention, decides the winner. The fix for both is exact: ranges should meet, not miss and not double up.
Mistake 3: the missing viewport meta tag
This is the classic, and it is not in the stylesheet at all. Without a <meta name="viewport"> tag in the page head, mobile browsers render the page on a desktop-width canvas, around 980 CSS pixels, then scale it down to fit. Your max-width of 767px never engages, because as far as the browser is concerned the viewport is never that narrow.
The check takes ten seconds: view the page source and confirm the tag is present with width=device-width in it.
Mistake 4: thinking in device pixels
A phone marketed with a 1170-pixel-wide screen does not give your layout 1170 pixels to work with. Media queries measure CSS pixels, and on high-density displays several physical pixels map to one CSS pixel, so that phone's viewport may be 390 CSS pixels wide. Breakpoints picked from a spec sheet land in the wrong places and match nothing.
Mistake 5: so many conditions that nothing matches
Because conditions join with "and", each one you add is another way for the query to fail. A query demanding a width range, a height range, an orientation and a media type may describe a screen that exists only in your head: the tablet that fits the width band is in the other orientation, the phone in the right orientation is too narrow.
The check is to ask of each condition: what real screen am I picturing, and does it pass every test at the same time? If you cannot name one, the query is decoration. Keep queries as short as the design allows; an empty field means no limit, which is often what you actually want.
How to check a query with the builder, step by step
- Open the Media Query Builder and start from a preset close to the range you intend, or enter exact pixel widths and heights yourself.
- Set the media type (screen, or all) and, only if the design depends on it, an orientation condition.
- Read the minimum and maximum fields as a pair; the builder flags a minimum above the maximum instead of emitting a dead query.
- Copy the complete
@mediablock, paste it into your stylesheet, and replace the placeholder comment inside with your CSS. - Test at the boundary widths: one pixel below, at, and one pixel above each breakpoint.
Worked example: the width nobody styled
The builder's basic phone query shows the shape. Set the media type to screen and only a maximum width of 767px, leaving the minimum empty:
@media screen and (max-width: 767px) {
/* your CSS here */
}
Now picture this paired with a larger-screen rule starting at a min-width of 769px. Every width is covered except 768px, precisely the width of a small tablet in portrait orientation, which gets no responsive rules at all. Moving the second query's minimum to 768px closes the gap, and the boundary test above, checking 767, 768 and 769, proves it.
Limitations and honest tradeoffs
The builder assembles the query; it does not write the layout CSS inside it, load your page, or test anything on a real device. The placeholder comment marks where your own rules go. And a validated query only proves the range is possible; whether the styles produce a good layout remains a visual judgement.
Common mistakes
- A minimum above the maximum. The range is empty and the styles are dead. Read the pair together, or let the builder catch it.
- Ranges that miss by one pixel. 767 then 769 leaves 768 unstyled. Make them meet exactly.
- Ranges that overlap. Two rule sets at one width, decided by source order.
- No viewport meta tag. Phones render at a virtual desktop width and width queries never engage.
- Breakpoints from the spec sheet. Physical pixels are not CSS pixels. Test on the device.
- Condition stacking. Every "and" is another chance to match nothing. Name a real screen that passes them all, or drop one.
FAQs
Why does my media query never apply? The usual causes are an impossible range (a minimum larger than the maximum), conditions so narrow that no real screen satisfies them, or a missing viewport meta tag, which leaves phones rendering at a virtual desktop width. Check each condition against a real screen size.
What happens if min-width is larger than max-width? The range is empty, so the query can never match any viewport. Nothing breaks visibly; the styles inside simply never apply. The Media Query Builder validates this combination and flags it.
Should breakpoint ranges touch or overlap? They should touch exactly. If one range ends at a max-width of 767px, the next should start at a min-width of 768px. Starting at 769px leaves 768px unmatched, while overlapping ranges apply two rule sets at once and let source order decide the winner.
Does the Media Query Builder test my website? No. It assembles the block from the fields you set and validates field-level mistakes such as a minimum above the maximum. It does not load your site or test styles on devices; that part is still yours.
Are the preset breakpoints official standards? No. The presets are widely used conventions based on common device sizes, not values set by any standards body. Adjust them to the widths where your own layout starts to strain.
Conclusion
A media query that never matches looks exactly like a working one, which is why these mistakes survive for months. Check the range, check the boundaries, check the head of the page, and build the query from fields so impossible combinations get caught before they ship. When a tablet in portrait needs its own treatment rather than a borrowed phone or desktop layout, our companion guide on writing a media query for tablets in portrait mode builds one condition by condition. For more guides in this series, see our Website and Webmaster Tools guides.
References
- MDN Web Docs, on media queries and the conditions they test: https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Media_queries/Using_media_queries
- web.dev (Google), on responsive design patterns and viewport behaviour: https://web.dev/learn/design