A media query fails in the worst possible way: silently. There is no error message, no red underline, nothing in the console. The block simply never applies. Most developers respond by rewriting the query at random, changing three things at once, and learning nothing when it starts working again.
There is a better way. Almost every dead media query dies from one of six causes, checkable in a fixed order. This guide walks that checklist, using the Media Query Builder on Ovatly as a reference instrument: it generates a block from the same conditions, validates the obvious range mistake, and gives you a known-good reference block.
Contents
- Quick answer
- Start with a known-good reference
- Check 1: minimum larger than maximum
- Check 2: block above the styles it must beat
- Check 3: no viewport meta tag on real phones
- Check 4: physical pixels, not CSS pixels
- Check 5: the conditions together match nothing
- Check 6: a typo in a feature name
- How to debug a media query, step by step
- Worked example: the query that could never fire
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
When a media query does nothing, check these six causes in order: a minimum width larger than the maximum width, the block sitting above the base styles it must override, a missing viewport meta tag, breakpoints written against physical pixels instead of CSS pixels, conditions combined so strictly that no screen satisfies them all, and a typo in a feature name. The fastest single move is to rebuild the same query in the Media Query Builder and diff its output against yours.
Start with a known-good reference
Debugging by staring at your own code has a flaw: you already believe it is right. A reference you did not type breaks that loop. The builder assembles breakpoint snippets from presets or exact pixel widths and heights, with an optional orientation condition and a media type of screen or all, and outputs a complete @media block ready to paste. Empty minimum and maximum fields mean no limit on that side, conditions combine with and, and the widths are viewport CSS pixels.
Generate the query you intended and place its block next to yours. If the two match and yours still fails, the problem lives in placement, the page, or the device: checks 2 to 4. If they differ, the difference is your first suspect.
Check 1: minimum larger than maximum
A query like min-width: 800px combined with max-width: 767px describes a screen that cannot exist, so the block never applies. Hand-typed CSS accepts this without a murmur. The builder does not: it validates obvious mistakes such as a minimum width larger than the maximum before you copy the block. If your ranges came from editing an older query, this is the likeliest cause.
Check 2: block above the styles it must beat
A matching query is not enough. When your block's rule and the base rule have the same specificity, the one that appears later in the stylesheet wins. A block pasted near the top of the file, above those base styles, loses every tie. Move breakpoint blocks after the base rules they adjust, and check for a later stylesheet re-asserting the base values.
Check 3: no viewport meta tag on real phones
This is the classic works-on-desktop failure. Resizing a desktop window changes the real viewport, so the query fires. A phone without a viewport meta tag instead lays the page out on a wide virtual viewport, commonly around 980 CSS pixels, and scales it down to fit. Your max-width: 767px condition is then honestly false. The fix is one line in the head, <meta name="viewport" content="width=device-width, initial-scale=1">, so the phone uses its real width.
Check 4: physical pixels, not CSS pixels
Media queries measure CSS pixels, and on high-density screens the two counts diverge. A phone whose panel has over a thousand physical pixels across may report a CSS width of only a few hundred. If you wrote breakpoints from the resolution printed on the box, your ranges aim at numbers the browser never sees. Test against the CSS width the device reports.
Check 5: the conditions together match nothing
Every condition joined by and must be true together. Width, height, orientation and media type each narrow the field, and stacking reasonable conditions can produce a combination no visitor has: a tall landscape phone under a strict height cap, for example. Remove one condition at a time until the query fires, then add back only what the design needs.
Check 6: a typo in a feature name
Browsers discard a media query they cannot parse, quietly. max-wdith, a missing closing parenthesis, or a colon typed as a semicolon all produce the same symptom: nothing happens. This is where the diff earns its keep: a one-letter difference is easier to spot side by side than by rereading your own line.
How to debug a media query, step by step
- Write down exactly when the block should apply: which widths, which orientation, which device.
- Open the Media Query Builder, enter the same conditions, and copy its block.
- Diff the two blocks character by character. Fix any difference and retest before touching anything else.
- Confirm the range is possible: minimum below maximum, both in CSS pixels.
- Check placement: the block must come after the base styles it overrides.
- Test on a real phone, not only a resized window, and confirm the page carries the viewport meta tag.
Worked example: the query that could never fire
A stylesheet carries this block, intended to stack a layout on small screens:
@media screen and (min-width: 800px) and (max-width: 767px) {
/* stacked layout */
}
It has never applied, on any device, and never will: no width is both at least 800px and at most 767px. Check 1 catches it, and the builder refuses to produce it in the first place. The intended query was the small-screen half alone, which the builder generates as @media screen and (max-width: 767px), the minimum field left empty to mean no lower limit. One deleted condition later, the layout stacks.
Limitations and honest tradeoffs
The builder validates the range mistake and produces clean syntax, but it cannot see your stylesheet, your HTML or your phone. Cascade order, the viewport tag and device behaviour are outside what a snippet generator can check, so checks 2, 3 and 4 remain manual. Its presets are widely used conventions from common device sizes, not official standards, so a builder block is a reference for shape and syntax, not a guarantee its widths suit your layout. No checklist replaces a real device for the final test: emulators approximate phone behaviour without reproducing every viewport quirk.
Common mistakes
- Changing three things at once. You learn that something worked, never what. One fix, one retest.
- Testing only in a resized desktop window. That skips the viewport and CSS pixel failures, both phone-only traps.
- Copying breakpoints from a tutorial aimed at other devices. Their widths describe someone else's layout and audience.
- Deleting the query and starting over. You throw away the evidence. Diff first; the fault is usually one character or one condition.
- Assuming a matching query must win. Matching only earns the right to compete in the cascade. Order and specificity still decide.
FAQs
My media query works on desktop but not on my phone. Why? Usually a missing viewport meta tag: without it, the phone lays the page out on a wide virtual viewport, so a max-width condition never matches. Second suspect: CSS pixels, since a phone with over a thousand physical pixels may report only a few hundred CSS pixels wide.
What happens if min-width is bigger than max-width? The query can never be true, so nothing inside it ever applies, and hand-typed CSS fails silently, with no error anywhere. The Media Query Builder flags that combination before you copy the block.
Does the order of rules in my stylesheet matter? Yes. When two rules have the same specificity, the one that comes later wins. A media query block placed above the base styles it is meant to override loses even when the query matches perfectly.
How do I check whether my query is typed correctly? Build the same conditions in the Media Query Builder and compare its block with yours character by character. A single typo in a feature name, such as max-wdith, makes the browser discard the whole query without telling you.
Why does my query fire at the wrong screen size? Media queries measure CSS pixels, not physical pixels. High-density screens pack several physical pixels into one CSS pixel, so a device advertising a very large resolution can still report a modest CSS width. Write breakpoints against the CSS figures.
Conclusion
A silent media query is not a mystery; it is one of six ordinary failures, and a fixed checking order finds it faster than rewriting. Keep the Media Query Builder open: its validated, generated block is the reference that separates a broken query from a broken page. For the one condition the builder cannot generate, see our guide to targeting dark mode with a prefers-color-scheme query. For more guides in this series, see our Website and Webmaster Tools guides.
References
- MDN Web Docs, on using media queries: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries
- MDN Web Docs, on the viewport meta tag: https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag