how come media query won't work for mobile device?

media query not working
media query breakpoints
media query breakpoints 2019
best way to write media queries
media query specificity
media query for desktop
how to use media query in bootstrap
css media query less than 768

As you can see from the screen, I do have a media query CSS

@media only screen and (max-width: 600px) {
  .block {
    background-color: lightblue;
    width: 100%;
    margin-top: 20px;

But for mobile device with under 600px, the block won't able to display lightblue background; but resize with desktop browser works.


detail code with here:

The comment from @Reza works, that is add viewport meta.

<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

Responsive Media Queries For Mobile Devices (With CSS Examples), that you are trying to override. In case the earlier ones are more specific, they can keep overwriting the new selector. My media queries do not work in Firefox (latest version). I have referenced my responsive.css files properly (I believe) and am certain I'm missing something in the CSS portion. Here is my HTML for the About page in question:

I don't know what mobile device you're testing on, but I'm assuming you're not aware of the difference between device pixels and actual CSS pixels: CSS pixels are an abstraction over the real pixels in your device's specs to make webpages appear consistent on all the different device sizes.


CSS pixels = Physical resolution / Device Pixel Ratio 

The Device Pixel Ratio itself is determined by each browser on each device independently.

On my phone, your codepen works fine and displays blue. I recommend checking out this codepen, which will reveal your Device Pixel Ratio and logical resolution. Most likely your device has a CSS width larger than 600px.

Media Query Styles Not Overriding Original Styles, "; this means (min-width: 20em) and (max-width: 20em) will both match a viewport that is exactly 20em wide. Media Queries For Columns. A common use of media queries, is to create a flexible layout. In this example, we create a layout that varies between four, two and full-width columns, depending on different screen sizes:

On my phone, given codepen example works without meta tag (color change, meta tag is just for scaling, so this means that @media query is read properly). Also, some new phones or phablets have virtual resolution 800px in portrait mode, so website should be tested on those devices.

If color doesn't change, try deleting Chrome cache on mobile phone:

I had the same problem two days ago, especially yesterday after Chrome was updated (seemed just to ignore any changes to @media queries, which showed properly on desktop in responsive mode). After testing website with Firefox for Android (worked properly), and also with Chrome failing to reflect some changes to CSS outside @media query (background-color), it was obvious that Chrome didn't load changed CSS file from the server, but used some older locally cached version. After deleting browsing cache, everything works as it should be (even after CSS file was changed a few times after this).

What are the rules for CSS media query overlap?, It could be a CSS3 media query mistake so simple that you've just overlooked it. If you test out your CSS media queries on a mobile device, you won't see the  I am using this code in my web page and I tried different settings for min-width but it take values only from the media query having least width. @media only screen and (min-width: 900px) { l

Where to put CSS3 Media Queries?, This is where media queries come in. Best of all? You won't need to learn HTML and CSS in depth to set up your media queries. This is  A Media query is a CSS3 feature that makes a webpage adapt its layout to different screen sizes and media types. Syntax @media media type and (condition: breakpoint) { // CSS rules } We can target different media types under a variety of conditions. If the condition and/or media types meet, then the rules inside the media query will be applied, otherwise, they won’t.

CSS3 Media Queries: Simple Gotchas & Easy Fixes, And CSS Media Queries are one of the most important parts of Responsive Design. then the Duration: 6:46 Posted: Apr 8, 2020 When you add the media query for body background make sure you are also adding media query to things that are fixed widths like your menu container. This could be your issue. I just visited your site on my Galaxy and you can scroll right. This should not be happening.

Mastering Media Queries [Support Series], I have no idea why my media query isn't working. (SOLVED) Just incase anyone else has a problem with @media query not h… With the comments I don't know why but when I've copied the code /* hasn't come through. It looks like Microsoft Edge has an issue with media queries if there the class has no fallback. This means that if a css class is only specified inside a media query it sometimes won't work correctly. So if the CSS looks like this: @media (max-width(123px){ .height-fix { height: 650px } } it wont work. It should to look like this:

  • Try to add: <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  • Why do device pixels matter at all? This confuses the matter terribly. CSS pixels are the only units you need to worry about when dealing with media queries and they are standardized regardless of if you are on a 4x screen or a 1x screen.
  • It matters because if he is using a tablet or large phone with a CSS width larger than 600px, his media query will not trigger, regardless of the width he thinks his device has / the specs say it has.
  • The OP posted a very clear screenshot of chrome in responsive mode.
  • Which he also stated does work as he expects. It is the mobile device that doesn't work. Maybe you should reread what OP stated ..., oh and upvote my answer ;)