How to Fix Media Query Not Working in WordPress

Media Query Not Working in WordPress

Introduction

You wrote a media query for your WordPress site. It should change the layout on phones. But nothing happens. The text stays huge, or the columns stay side by side. This is a common and annoying fault. The good news is that the cause is nearly always small.

A media query is a CSS rule with a condition. It tells the browser to use some styles only at certain screen widths. When the condition fails, the browser skips those styles. When another rule is stronger, the browser also skips them. Both cases look the same to you.

The problem often starts after a change. You may have switched themes or added a page builder. You may have turned on a speed plugin. Or you may have pasted CSS from a tutorial. This guide shows the signs, the real causes, and eight fixes. Each fix tells you how to check first, then how to confirm the result.

Signs That Show a Media Query Is Not Working in WordPress

The clearest sign is a layout that never changes. You shrink the browser window, and the page looks the same. Your mobile font size, spacing, or hidden element rule does nothing. The desktop design simply gets squeezed or cut off.

Sometimes the rule works in one place and fails in another. It may work when you resize a desktop window. Yet a real phone still shows the desktop layout, only tiny. That pattern points to a missing viewport tag. The opposite can also happen. The phone looks right, but your resized desktop window does not.

You may also see a split between visitors. Logged-in users see the mobile styles. Logged-out visitors see the old design. That split points to cached CSS. Another sign is a rule that works in the theme preview but fails on pages made with a builder.

These signs are different from CSS that never loads at all. If none of your new CSS shows at any width, read our guide on WordPress CSS changes not showing first. This guide is for styles that load on desktop but fail inside a media query.

Reasons Why a Media Query Is Not Working in WordPress

There are eight real causes. Each one breaks the query in a different way. Read them once, then use the steps to find yours.

The Test Itself Is Misleading

Media queries measure CSS pixels, not the pixels on the glass. A phone may have 1080 real pixels across. The browser still reports about 400 CSS pixels. Browser zoom changes the number too. At 200 percent zoom, a 1400 pixel window acts like 700. So a query can seem broken when only the test is wrong. People also test at the exact edge value and misread the result.

The Browser Is Loading Old or Optimised CSS

Caching plugins store a copy of your pages and stylesheets. A CDN and your browser do the same. You save a new media query, but visitors still get the old file. Speed plugins add a second risk. They join many CSS files into one and shrink them. Joining can change the order of rules. Shrinking can break a file that has one small error.

The Viewport Meta Tag Is Missing

Phones pretend to be wide screens by default. Without a viewport tag, a phone may draw the page about 980 pixels wide. Then it shrinks the result to fit the glass. Your query asks for a width under 768 pixels. The phone reports 980, so the query never matches. The tag tells the phone to use its true width. Most modern themes add it, but old or hand-built themes may not.

The Media Query Has a Syntax Mistake

Browsers are strict with media queries. A missing space after the word “and” makes the whole query invalid. A missing unit does the same, such as 768 with no “px”. A missing closing brace is worse. It can swallow every rule that follows it. The browser does not warn you. It just drops the block in silence.

The Rules Are in the Wrong Order

A media query does not make a rule stronger. It only switches the rule on or off. When two rules use the same selector, the later one wins. So if your normal rule sits below the query, it wins every time. This is the most common cause in pasted CSS. It also happens when two stylesheets load in an unexpected order.

A Stronger Rule Is Overriding It

CSS ranks rules by how specific their selectors are. A rule with an ID beats a rule with only a class. A long selector from your theme can beat your short one. Inline styles beat both. Page builders often write inline styles or very specific selectors. Rules marked “!important” beat nearly everything. Your query matches, but its styles lose the contest.

The Breakpoint Values Are Wrong or Overlap

A breakpoint is the width where the layout changes. Mixing “min-width” and “max-width” by mistake flips the logic. Two queries can also overlap. Say one uses a max of 1024 and a later one uses a max of 768. Listed in the wrong order, the wider one wins on phones. Page builders also have their own breakpoints. If yours differ from theirs, the two sets fight in the gap between them.

The Stylesheet Loads With the Wrong Settings

WordPress loads stylesheets through a function called wp_enqueue_style. That function accepts a media value, which is “all” by default. If a file loads with “print”, the screen ignores it fully. If it loads with its own width query, your inner queries only run inside that range. A child theme can also load its stylesheet before the parent. Then the parent’s rules land last and win.

How to Fix a Media Query Not Working in WordPress (Step by Step)

Work through these steps in order. They start with safe checks and end with code changes. Stop as soon as your mobile styles appear.

Step 1: Test the Query the Right Way

This step deals with the misleading test. Zoom and device pixels change the width your browser reports. So first make sure the fault is real. Open your page in Chrome or Firefox on a desktop. Press Ctrl and 0 to reset zoom to 100 percent. On a Mac, press Cmd and 0.

Now right-click the page and choose Inspect. Click the small phone and tablet icon in the toolbar. This opens the responsive view. Type an exact width in the box at the top, such as 375. Do not test at your breakpoint value itself. Test well below it and well above it.

A healthy query changes the layout as you cross the breakpoint. A broken one changes nothing at any width. If the layout changes here, your query works. The earlier test was wrong, and you can stop. If nothing changes, keep the responsive view open. You will use it in the next steps.

Step 2: Clear Every Cache and Pause CSS Optimisation

This step deals with old or optimised CSS. A stored copy hides your new query from the browser. To confirm it, open the page in a private window while logged out. Then compare it with your logged-in view. If only the logged-in view is right, a cache is the cause.

Start with your caching plugin. Open its settings in the dashboard and use the option that purges all cache. Next, purge your CDN if you use one. Many hosts also have a cache button in their control panel. Last, hard refresh the page with Ctrl, Shift and R.

If the query still fails, look at CSS optimisation. Find the settings for minify CSS and combine CSS in your speed plugin. Turn both off, save, and purge again. This change is safe and easy to undo. Reload the page in the responsive view.

If the query now works, the optimiser was the cause. Turn minify back on and test. Then turn combine back on and test again. Leave off the one that breaks the layout. If nothing changed, switch both back on and move to Step 3. Our guide on WordPress not updating immediately covers stubborn caches in more depth.

Step 3: Check for the Viewport Meta Tag

This step deals with the missing viewport tag. Without it, a phone reports a false wide width. So queries for small screens never match. The telltale sign is simple. The query works in a resized desktop window but fails on a real phone.

To check, open your site and press Ctrl and U to view the source. Press Ctrl and F and search for the word viewport. A healthy site shows one line like this near the top:

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

If the line is there, this is not your cause. Move to Step 4. If it is missing, the theme needs it. This means editing a theme file, so back up your site first. Better still, make the change on a staging copy. Never edit the parent theme directly, because an update will erase your work.

Use a child theme instead. Copy the theme’s header.php file into the child theme folder. Open the copy and find the opening head tag. Paste the line above just below it and save. For a block theme, you should not need this. WordPress adds the tag for block themes by itself.

Now reload the page on a real phone. The page should fit the screen, and your mobile styles should apply. If the tag is present and the query still fails, go on.

Step 4: Check the Media Query Syntax

This step deals with syntax mistakes. One wrong character makes the browser drop the whole block. To confirm it, use the Inspect panel from Step 1. Click the element that should change. Look at the Styles list on the right. If your media query rule is not listed at all, the browser rejected it or never loaded it.

Now open the place where you saved the CSS. That may be the Customizer, under Appearance, in Additional CSS. In a block theme, open Appearance, then Editor, then Styles. Open the three-dot menu there and choose Additional CSS. Compare your code with this correct pattern:

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

Check four things. There must be a space after the word “and” if you use it. Every number needs a unit, such as px. Each width sits inside round brackets. And the block needs two closing braces, one for the rule and one for the query. Count your braces from top to bottom.

Fix what you find and save. WordPress may refuse to save CSS with uneven braces. Treat that message as a helpful clue. Reload the page and inspect the element again. Your rule should now appear in the Styles list. If it appears but is crossed out, the next two steps are for you.

Step 5: Move the Media Query Below the Normal Rule

This step deals with rule order. A query adds no strength to a rule. When selectors match, the rule that comes later wins. So a normal rule placed after the query cancels it. You can confirm this in the Inspect panel. Your query rule shows as crossed out. Just above it sits a rule with the same selector.

Open your CSS again. Find the normal rule and the query that changes it. The normal rule must come first. The query must come after it. The safest habit is simple. Keep all your media queries at the very bottom of your custom CSS.

The order of the queries matters too. With max-width queries, list the widest first and the narrowest last. For example, put 1024 before 768, and 768 before 480. With min-width queries, do the reverse. Start with the smallest and end with the largest.

Save and reload in the responsive view. The crossed-out line should now be active. Drag the width back and forth across the breakpoint to be sure. If the rule is still crossed out, a stronger selector is at work. Go to Step 6.

Step 6: Beat the Stronger Rule

This step deals with stronger rules. Your query matches, but another selector outranks it. The Inspect panel shows this clearly. Your rule is crossed out. The winning rule sits above it with a longer selector. It may also show as an inline style on the element itself.

Start by copying the winning selector. Then use that same selector inside your media query. Equal strength plus later position means your rule wins. For example, your rule might use “.menu a”. The theme might use “#site-header .menu a”. Change yours to match the theme’s version.

Inline styles need a different approach. A page builder usually writes them. Open the page in the builder and select the element. Switch the builder to its mobile or tablet view. Set the value there instead of in custom CSS. The builder then writes its own responsive rule.

Use “!important” only as a last resort. It works, but it makes later changes harder. Add it to one property, not the whole block. Save, reload, and inspect again. Your rule should be active with no line through it. If two plugins fight over the same element, see our guide on finding a WordPress plugin conflict.

Step 7: Correct the Breakpoint Values

This step deals with wrong or overlapping breakpoints. The query runs, but at the wrong widths. To confirm it, drag the responsive view slowly from wide to narrow. Watch the width number at the top. Note the exact width where the layout changes. Compare that with the width you wanted.

If the layout changes on wide screens only, the logic is flipped. You likely wrote “min-width” where you meant “max-width”. Remember the plain meaning. A max-width of 768 means 768 pixels and narrower. A min-width of 768 means 768 pixels and wider.

Next, look for gaps and overlaps. If one query ends at a max of 768, start the next at a min of 769. Otherwise both apply at exactly 768. Then check your page builder. Open its site settings and find the breakpoints or responsive section. Write down its mobile and tablet values. Use those same values in your own CSS.

Matching values removes the odd zone where two layouts mix. Save and drag the width across each breakpoint again. The layout should now switch at the width you expect. The same check helps when a menu fails on phones. Our guide on a missing mobile menu in WordPress explains that case.

Step 8: Check How the Stylesheet Is Loaded

This step deals with stylesheet loading. It mostly affects child themes and custom code. The file may load for the wrong media type. Or it may load before the file it should override. To confirm it, view the page source again. Search for the name of your stylesheet.

Look at the link tag for that file. Find the part that says media. A healthy tag says media=”all”. If it says “print”, screens ignore the file. If it holds a width query, your rules only run inside that range. Also note where your file sits. It should appear after the parent theme’s stylesheet.

The fix is in the child theme’s functions.php file. A mistake in that file can take the whole site down. Back up first, and test on staging if you can. Keep FTP or your host’s file manager open, so you can undo the edit. Then find the line that loads your stylesheet.

wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ), '1.1', 'all' );

The last value is the media type. Set it to “all” or remove it. The array in the middle names the parent handle. That makes WordPress load the parent first. Use the handle your parent theme really registers. Raise the version number so browsers fetch the new file.

Save, purge your cache, and view the source once more. Your file should now load last with media set to all. Test the query in the responsive view. If it still fails after all eight steps, the cause is likely custom code. At that point, expert help will save you time.

Best Practices to Prevent Media Query Problems in WordPress in Future

Most of these faults are easy to prevent. Start with how you test. Always check new CSS at 100 percent zoom. Use the responsive view at fixed widths, then confirm on one real phone. That habit catches misleading tests and missing viewport tags early.

Keep your custom CSS tidy. Put normal rules first and all media queries at the bottom. Order the queries from widest to narrowest when you use max-width. Pick one set of breakpoints and use it everywhere. If you use a page builder, copy its values. This stops order problems and overlapping ranges.

Write selectors with care. Match the theme’s selector instead of reaching for “!important”. Set responsive values inside the builder when the builder owns the element. Paste new CSS in small pieces and test each one. A syntax slip is then easy to spot.

Treat caching as part of every CSS change. Purge the plugin cache, the CDN, and the browser after each edit. Test again after you change any speed plugin setting. Make theme file edits only in a child theme. Take a backup before you touch header.php or functions.php.

Last, test your layouts after every theme, builder, or plugin update. Updates can change selectors, breakpoints, and load order. A staging site lets you check all of this safely. Make sure update notices reach the right inbox as well. Our guide on how to change the admin email in WordPress shows how to set that address.

Conclusion

A media query that fails in WordPress is rarely a deep fault. The signs are clear once you know them. The layout does not change at small widths. Or it changes on desktop but not on a phone. Or logged-out visitors still see the old design.

Eight causes sit behind those signs. They are a misleading test, cached CSS, and a missing viewport tag. They also include syntax slips, wrong rule order, and stronger selectors. The last two are bad breakpoint values and stylesheet loading settings. Each one has a simple check in the browser’s Inspect panel.

Work through the steps in order. Test properly, clear the caches, and check the viewport tag. Then fix the syntax, the order, and the selector strength. Finish with the breakpoints and the way the file loads. Verify after every change, so you know which step worked.

Good habits keep the problem away. Keep queries at the bottom, match your builder’s breakpoints, and purge caches after edits. Back up before you edit theme files. For more detail on CSS rules, see the MDN guide to media queries and the WordPress reference for wp_enqueue_style. If your layout still breaks on mobile, our WordPress support team can find the cause for you.