Why Is My Media Query Not Working?

Media query not working problems usually happen when the browser is reading a different viewport, a different CSS rule, or a more rigid layout than the one you think you are testing.

Responsive CSS Fix

Why is my media query not working?

If your mobile styles are not applying, your breakpoint seems ignored, or your layout stays stuck in desktop mode, the browser is usually not being random. The real issue is usually a missing viewport tag, invalid syntax, CSS order, specificity, cache, or a rigid layout that makes the media query look broken even when it is actually firing.

  • Viewport setup
  • Breakpoint logic
  • CSS cascade
  • Rigid layout traps

What the bug looks like

Your CSS says mobile should be one column, but the page stays in desktop mode. Or your media query changes one thing, but the layout still overflows and looks broken.

Why it happens

A media query does not magically make a layout responsive. It only applies CSS under a condition. If setup, cascade, or structure is wrong, the result still breaks.

What usually fixes it

Confirm the viewport tag, test the breakpoint in DevTools, inspect overridden rules, then replace rigid layout rules with flexible responsive patterns.

Error 1

Missing viewport tag makes mobile CSS look ignored

This is one of the most common reasons a media query does not work on mobile. Without the viewport meta tag, the browser may render the page as a wide desktop canvas and scale it down. Your breakpoint may not match the real screen the way you expect.

Broken code

Missing viewport
<head>
  <title>My Page</title>
  <link rel="stylesheet" href="style.css">
</head>

@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

Broken visual result

Mobile acts like desktop
Card 1
Card 2
Card 3
The page is still behaving like a wide desktop canvas, so the mobile layout feels ignored.

Correct code

Real mobile viewport
<head>
  <meta name="viewport"
        content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="style.css">
</head>

@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

Fixed visual result

Viewport matches device
Card 1
Card 2
Card 3
The browser now treats the screen as a real mobile viewport, so the breakpoint can behave correctly.
Error 2

Invalid media query syntax silently breaks the rule

Media query syntax is easy to almost get right. A missing space, missing unit, wrong parenthesis, or forgotten brace can make the browser skip the rule or read it differently than you intended.

Broken code

Syntax trap
@media screen and(max-width: 768px) {
  .menu {
    display: none;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}

Broken visual result

Breakpoint ignored
Desktop nav still visible
Card
Card
Card
The CSS looks close, but the condition is malformed, so the mobile rule does not behave as expected.

Correct code

Valid condition
@media screen and (max-width: 768px) {
  .menu {
    display: none;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}

Fixed visual result

Mobile rule applies
Compact mobile header
Card 1
Card 2
Card 3
The same layout now stacks because the media query condition is valid and readable.
Error 3

The media query works, but CSS order overrides it

The browser may be applying your media query correctly, then immediately replacing it with a later rule. This is why media queries can “work” in DevTools but still not change what you see on the page.

Broken code

Later desktop rule wins
@media (max-width: 768px) {
  .card-title {
    font-size: 18px;
  }
}

.card-title {
  font-size: 36px;
}

Broken visual result

Mobile rule crossed out

Huge title on mobile

The media query fires, but the later desktop rule wins the cascade.

@media font-size: 18pxoverridden
later font-size: 36pxwins

Correct code

Mobile rule comes after
.card-title {
  font-size: 36px;
}

@media (max-width: 768px) {
  .card-title {
    font-size: 22px;
  }
}

Fixed visual result

Mobile rule wins

Readable mobile title

The mobile rule appears later, so the cascade now matches the responsive intention.

base font-size: 36pxbase
@media font-size: 22pxwins
Error 4

The breakpoint fires, but the layout is still rigid

This is the grown-up version of the media query bug. The media query is not dead. The layout is still too rigid. A fixed-width wrapper, a wide grid, a long code block, or an image without responsive limits can make the page look broken even after the breakpoint activates.

Broken code

Breakpoint fires, layout still breaks
.wrapper {
  width: 1200px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 320px);
}

@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

Broken visual result

The wrapper is still 1200px
Mobile breakpoint active
Wide wrapper
Still overflowing
Not responsive
The media query changed the grid, but the parent still forces a desktop width.

Correct code

Flexible parent and grid
.wrapper {
  width: min(100%, 1200px);
  margin-inline: auto;
  padding-inline: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

Fixed visual result

Parent can shrink
Responsive layout
Card 1
Card 2
Card 3
Now the wrapper and grid both cooperate with the breakpoint.
Premium pattern

A production-minded media query setup

The best responsive fix is not just one media query. It is a layout system that starts flexible, uses safe grid tracks, lets children shrink, protects images, and only uses breakpoints to adjust behavior—not to rescue broken desktop code.

Premium code

Flexible first
.layout {
  width: min(100%, 1120px);
  margin-inline: auto;
  padding-inline: clamp(16px, 4vw, 32px);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: clamp(16px, 3vw, 28px);
}

.card,
.card * {
  min-width: 0;
}

.card img {
  display: block;
  max-width: 100%;
  height: auto;
}

@media (max-width: 768px) {
  .layout {
    padding-inline: 16px;
  }

  .card-title {
    font-size: clamp(24px, 8vw, 34px);
  }
}

Premium visual result

Flexible before breakpoint
Production-ready cards
Safe card width
No overflow trap
Breakpoint becomes lighter
The layout is responsive even before the media query has to do heavy work.

Fast practical rule

If your media query is not working, do not start by changing random breakpoint numbers. First confirm the viewport tag, then test whether the rule is firing in DevTools, then check whether another rule or a rigid parent is still winning.

Debug checklist

  • Confirm the page includes <meta name="viewport" content="width=device-width, initial-scale=1">.
  • Resize the page in DevTools and confirm whether the media query is actually firing.
  • Check the media query syntax for missing spaces, braces, parentheses, units, and invalid conditions.
  • Inspect whether a later CSS rule is overriding the media query.
  • Check whether a stronger selector is beating your mobile selector.
  • Verify whether the breakpoint should use max-width or min-width.
  • Look for a fixed-width wrapper, wide grid track, long word, code block, image, table, or child element that refuses to shrink.
  • Clear browser, plugin, and CDN cache if your CSS changes are not showing at all.
Best first move Use DevTools to see whether the media query is active before changing the breakpoint value.
Most overlooked cause The viewport tag is missing, so the browser never behaves like the real mobile screen.
Most frustrating cause The media query works, but a later CSS rule silently overrides it.
Better mindset Media queries should tune a flexible layout, not save a layout that was built rigid from the beginning.

Final takeaway

A media query not working rarely means the browser is broken. Most of the time, the browser is following the rules exactly: the viewport is wrong, the condition is invalid, the cascade is overriding the rule, specificity is too strong, cache is stale, or the layout is still too rigid to respond.

Start by proving whether the media query is active. Then debug the cascade. Then fix the structure. Once the layout is flexible first, media queries become precise adjustments instead of emergency rescue patches.

Want more fixes like this?

Browse more responsive debugging guides or jump to the full FrontFixer library.

Fix responsive design not working

Responsive design usually stops working when one part of the layout refuses to shrink, wrap, stack, or respect the viewport. The fix is not always another media query. The real fix is finding the rigid element that is forcing desktop behavior on a smaller screen.

Responsive Design Fix

Why Is My Responsive Design Not Working?

Responsive design can look confusing because the page may work on desktop, partially change on mobile, and still feel broken. In most cases, the browser is not ignoring your CSS. One layout rule, one child element, one missing viewport tag, or one bad breakpoint is preventing the page from adapting correctly.

  • Mobile layout bugs
  • Viewport and breakpoint issues
  • Overflow and fixed-width debugging

What the bug looks like

The page scrolls sideways, cards stay in desktop columns, text runs outside its box, images overflow, or mobile styles seem to do nothing.

Why it happens

The layout contains a rigid assumption: a fixed width, a non-wrapping row, a wide child, a missing viewport setup, or a breakpoint that does not match the real failure point.

What fixes it

Start with the viewport, remove fixed widths, make media flexible, allow children to shrink, and adjust breakpoints only after you find what is actually breaking.

The simple rule behind responsive design bugs

Responsive design does not fail randomly. It fails when the layout is asked to fit a smaller screen but one part of the page refuses to adapt.

That stubborn part can be a container with width:1200px, a grid that never stacks, a flex row that never wraps, a long word that cannot break, an image without max-width:100%, or a media query that activates too late.

The fastest fix is usually not adding more CSS. The fastest fix is finding the one rule that is forcing the page to behave like desktop.

Error 1

The viewport meta tag is missing

This is the first thing to check. Without the correct viewport tag, a mobile browser may use a virtual desktop-sized viewport and scale the page down. That can make responsive CSS feel like it is broken even when your CSS rules exist.

Broken code

Missing viewport
<head>
  <title>My Page</title>
</head>

Broken visual result

Mobile behaves like desktop
Desktop layout squeezedThe browser is not using the screen width the way you expect.

Correct code

Viewport setup
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My Page</title>
</head>

Fixed visual result

Screen width is respected
Mobile viewport worksThe layout can now respond to the real device width.
Error 2

A fixed-width container is forcing desktop layout

A container with a hard width is one of the most common reasons responsive design fails. If the container is wider than the screen, the page has no choice: it creates horizontal overflow.

Broken code

Rigid width
.container {
  width: 1200px;
  margin: 0 auto;
}

Broken visual result

Container is too wide
1200px containerThis box refuses to fit inside the smaller viewport.

Correct code

Flexible container
.container {
  width: min(100%, 1200px);
  margin-inline: auto;
  padding-inline: 16px;
}

Fixed visual result

Container can shrink
Fluid containerThe container respects the screen while keeping a maximum desktop width.
Error 3

The grid does not stack on smaller screens

A desktop grid can look perfect at full width and then collapse badly on mobile. The problem is often that the grid keeps too many columns for too long.

Broken code

Desktop grid only
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

Broken visual result

Three columns are squeezed
CardToo narrow.
CardToo narrow.
CardToo narrow.

Correct code

Mobile stack
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

.card {
  min-width: 0;
}

@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

Fixed visual result

Cards stack cleanly
Card oneFull mobile width.
Card twoFull mobile width.
Card threeFull mobile width.
Error 4

Long content is creating hidden overflow

Sometimes the layout itself is mostly correct, but one piece of content is too stubborn. Long URLs, code snippets, product names, labels, buttons, and unbroken text can push the page wider than the viewport.

Broken code

No wrapping
.card-title {
  white-space: nowrap;
}

Broken visual result

Text refuses to wrap
SuperLongUnbrokenResponsiveLayoutBugExampleThe text pushes past the card.

Correct code

Safe wrapping
.card-title,
.long-text,
.url,
.label {
  overflow-wrap: anywhere;
}

Fixed visual result

Text can break safely
SuperLongUnbrokenResponsiveLayoutBugExampleThe content now stays inside the card.
Error 5

The breakpoint is chosen by habit, not by the layout

A breakpoint should be based on where the layout actually starts failing. If you copied a common breakpoint without testing the real content, your media query may activate too late.

Broken code

Too late
@media (max-width: 480px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

Broken visual result

Breakpoint fires too late
Column 1cramped
Column 2cramped
Column 3cramped

Correct code

Layout-based
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

Fixed visual result

Layout stacks before breaking
Section 1enough space
Section 2enough space
Section 3enough space

Fast practical rule

If responsive design is not working, do not start by adding random breakpoints. First ask: what is the widest, most rigid, least flexible element on this page right now?

Recommended baseline

Responsive foundation

This is not a magic reset, but it gives most layouts a safer responsive foundation before you debug specific components.

<meta name="viewport" content="width=device-width, initial-scale=1">

.container {
  width: min(100%, 1200px);
  margin-inline: auto;
  padding-inline: 16px;
}

.layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.layout > * {
  min-width: 0;
}

img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

pre,
code {
  max-width: 100%;
  overflow-x: auto;
}

.long-text,
.url,
.label {
  overflow-wrap: anywhere;
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

Why this baseline helps

It respects the real viewportThe viewport tag tells mobile browsers to use the device width properly.
It prevents rigid containerswidth:min(100%, 1200px) keeps the layout fluid while preserving a maximum desktop width.
It lets children shrinkmin-width:0 helps grid and flex children stop forcing overflow.
It handles real contentImages, videos, code blocks, URLs, and long labels are common sources of mobile layout bugs.

Debug checklist

  • Confirm the page includes <meta name="viewport" content="width=device-width, initial-scale=1">.
  • Inspect the page at the width where the layout first starts failing.
  • Look for fixed widths like width:1200px, min-width:900px, or wide components.
  • Check images, videos, iframes, tables, code blocks, buttons, and long text.
  • Use DevTools to find the element causing horizontal overflow.
  • Check whether grid or flex children need min-width:0.
  • Make sure columns stack before the layout becomes cramped.
  • Choose breakpoints based on where the layout breaks, not only on device names.
Best first moveOpen DevTools, shrink the viewport slowly, and find the exact width where the layout starts breaking.
Most common false fixAdding more media queries without finding the fixed-width or overflowing element.
Most overlooked causeA single child inside grid or flex that cannot shrink because it needs min-width:0 or safer wrapping.
Better mindsetResponsive debugging is less about memorizing breakpoints and more about removing rigid layout assumptions.

When overflow is the real problem

A page can look like the entire responsive system is broken when the real cause is just one element that is wider than the viewport.

This is common with tables, code blocks, long URLs, carousels, images, embeds, and button groups.

If your page scrolls sideways, read Fix overflow causing horizontal scroll.

When grid is the real problem

If only one grid section breaks on mobile, the issue may not be your whole responsive strategy. The problem may be the grid columns, child sizing, or lack of stacking.

In that case, read Fix CSS Grid breaking on mobile.

When HTML structure is the real problem

Sometimes the CSS looks complicated because the HTML structure is fighting against the layout. Extra wrappers, missing containers, weak grouping, or badly nested elements can make responsive behavior fragile.

If the layout keeps needing patches, read Fix HTML structure problems.

When flex items refuse to shrink

Flex layouts can also create responsive problems when an item keeps its content width and refuses to shrink inside the available space.

If that sounds familiar, read Fix flex item shrinking with fixed width.

FrontFixer Live Inspector

Preview the responsive behavior before changing breakpoints.

Before adding another media query, paste a small version of the layout into the FrontFixer Live Inspector. You can switch between desktop, tablet, and mobile preview modes and check whether the real issue is a fixed container, a grid that refuses to stack, long content, or a missing responsive rule.

The inspector is a no-AI, no-server, rule-based testing space for isolated HTML and CSS snippets. Use it before moving a responsive patch into WordPress, your theme, or your production CSS.

Final takeaway

When responsive design is not working, the browser is usually exposing one rigid decision that desktop was hiding.

Start with the viewport. Then find fixed widths, overflowing children, non-wrapping content, grid or flex items that cannot shrink, and breakpoints that fire too late.

Once the stubborn element is fixed, the rest of the responsive layout usually becomes much easier to control.

Need more responsive fixes?

Browse the responsive cluster or jump back to the full FrontFixer library to keep debugging faster.