Media Queries for Standard Devices

If you think responsive's simple, I feel bad for you son. We got 99 viewports, but the iPhone's just one.
—Josh Brewer, March 10, 2010

A major component of responsive design is creating the right experience for the right device. With a gazillion different devices on the market, this can be a tall task. We've rounded up media queries that can be used to target designs for many standard and popular devices that is certainly worth a read.

If you're looking for a comprehensive list of media queries, this repository is a good resource.

If you're reaction to this is: you should never base your breakpoints on devices!! You have a good point. Justin Avery has a nice post on the possible pitfalls of using device-specific breakpoints. Choosing breakpoints based on your design and not specific devices is a smart way to go. But sometimes you just need a little help getting one particular situation under control.

Just read your post on using CSS for alternate styles for websites based on screen resolution. Great post.

I’m wondering if I can pay you to make me a simple template for HTML emails (that look like text) that looks good in mobile devices and desktop. Here’s the specs…

If the screen size is not mobile device then I need the text area to wrap at 350px.

If the screen size is mobile device then I want the text to wrap 100% across the screen (for either landscape or non-landscape) with a max width of 350px (in case of something like landscape mode iPad).

I need the text itself to be style font size +1 (so it looks slightly larger then the users normal email messages).

What I’m looking to avoid is using a 350px table to wrap the text and then having the iPhone shrink the text down smaller then normal… Requiring the user to take an extra step zooming in.

Also looking to avoid using end of line breaks at 350px and having those breaks end up mid screen on a mobile device (looking horrible).

Should be pretty simple for someone into this stuff. Let me know if you can do it and how much.

Just FYI, this is impossible if you plan to support all email clients. Gmail strips out the head of your message so media queries wont work. The best you can do is build a fluid layout and use text-size-adjust.

I’m just at the base of my learning curve on using alternate stylesheets for different devices. Following your example elsewhere I’ve sort of got it working. I’m testing it on my HTC Desire Android and for it to work on this phone I’m having to set as follows:

Nexus S reports 533 Pixels in landscape mode. so none of the above snippets will work if the phone is in landscape mode when you navigate to your site. my iPod on the other hand always reports 320px in portrait, as well as in landscape mode. Same for iPhone 4. It always reports 320px.

In regards to the media queries working on android browser. I Use Dreamweaver CS5.5. When I tested there was no change .
When I tested in landscape view it takes the default web browser screen width it is not device screen width.

When I use this to request a stylesheet for retina displays:
<link rel=’stylesheet’ type=’text/css’ href=’/css/mobile-retina.css’ media=’only screen and (-webkit-min-device-pixel-ratio: 2)’/>

I can’t get the W3 Validator to validate this. The error is: Bad value only screen and (-webkit-min-device-pixel-ratio: 2) for attribute media on element link: Expected a letter at start of a media feature part but saw – instead.

Is there a way of using the value “-webkit-min-device-pixel-ratio” mentioned in this post in a way so that it’s ‘valid’?

I this thread outdated please? I there more up to date guide for standard media queries??

I am sort of a newbie to media queries, so please excuse me if I seem out of touch with the latest media queries code. However, I am just reading these comments for the first time and they are over 3 years old. Does this site have an updated thread please??

i am writing right now is a page that will change the background image for each screen device because the desktop version is going to have hi-res photos on it. So, I don’t want to make mobile people download these super large images. I want my CSS files to be seperate so i am writing my media queries like this for example:

So a quick question. IF i visit a page that uses media queries does the browser download all of the style sheets or just the one that has been targeted? In my case, the styles.css should always load and then the other media queried stylesheets will load depending if they are true or not.

Your questions does not have a 100% definite answer, however I was researching this last week and came to one straight forward way of explaining this. If you are using display:none, you have a better chance of that element not being rendered by the browser. While if you are using visibility:hidden, the element you are configuring will be preloaded by your browser. Basically, it all depends on how the change takes place in your stylesheet to make the object hidden or shown – and of course which browser/platform/device the user is accessing from.

If you place all css in one file (including media queries), the device will download all assets regardless of the devices dimensions, so while you might use display:none to completely remove the element from the architecture of the website, it’s assets are still downloaded.

You are best to use a global style sheet, then target each break point setting with it’s own css file, this way ONLY that file and it’s assets will be targeted.

If you load desktop images in your global style sheet, then target smaller devices with smaller images, overriding the larger, you will be loading both the large and smaller image – even though the larger is not being displayed, it is being loaded, thereby slowing down the load time of the site for mobile users.

Always best to use separate media query files to target the devices within the break point range … and always use min and max settings to target these devices, because if you use only min size and overwrite by the next larger size (or smaller size) you are still loading all assets.

Is it possible to target the iphone4+ with a separate media query than other smart phones with the same min/width size

I ask because my responsive site (http://www.cortac.com) is shaping up nicely on an iPhone4+. However, in older (2 year old) Android’s, etc., the footer doesn’t *stick*, and I was hoping to simply have the footer display: none;

However, by doing so, that also kills my iphone4+ styling where I *do* want the footer to display. The problem is that the iphone4+ and the normal *smartphone* min/max dimensions are targeting the same dimensions of 320 and 480 respectively and I am unable to get separate devices with same width/height ratios to be targeted differently without overriding each other. Any online articles that talk about this would be greatly appreciated!

Gorgeous site, Jeremy! And I really like how you’ve broken it up with media queries. I stumbled on this post searching for the same problem you had – getting everything to look the same cross-phone-browsers. I think this thread may help me. Thanks for posting and keep up the awesome work.

You can not target specific devices with CSS … that’s where adaptive design comes into play by mixing together both javascript (or jquery) and css to target specific devices, set break points, and anything else css can not do, then apply the styles associated by the Adaptive targeting.

Amit Nagar! And I really like how you’ve broken it up with media queries. I stumbled on this post searching for the same problem you had – getting everything to look the same cross-phone-browsers. I think this thread may help me. Thanks for posting and keep up the awesome work.

That should work right? Just put that in your main css file where you hide the footer but then add a style in there to display it…

Also, i checked out the website too, looks great. One question I have is when i collapse the browser i notice that you always use the same set of images. Are you planning to keep it that way or will you optimize it for mobile devices by making the background not as big.

I’ve made my site so that it loads a different background image depending on what kind of device it is. I don’t want to download a 150kb-200kb background on my phone when i don’t have too.

Robbie, thank you for your response. I do have the styles for the retina display only, in addition to regular smartphones, and it does not seem to work on distinguishing between the two. If I eliminate the footer for normal smartphones, it overrides the retina styles regardless. Seems to be all or nothing so far.

Yes, thank you for your observation. I indeed plan on loading in smaller background images for the mobile version. I just have not added in those media queries yet, as this is a responsive experiment for me in progress.

My issue is the same as Marks. I am currently using Bootstrap and it seems like the layout changes should be made when the page is vertical in the ipad, but the layout doesn’t change unless I alter the media queries from 768px to 769px. I’m sure this isn’t the way it’s supposed to be done…

I used about media queries in a recent project, when I enter into landscape mode from portrait mode on iPad it appears scaled i.e. its already zoomed. I want it to show on original page zoom on both portrait and landscape mode.

You are not the only one with safari issues. I am having the same issues with safari picking up @media css as well in ANY resolution. the problem is i did a @media body {overflow:hidden} and safari will not scroll now lol

You said match every screen device with over 320 pixels. That is every device except very old phones, and you asked it to look and device-width, not width, so it does not care about the size of your browser window at all… only the devices width.

I am a GUI designer. When designing for a mobile site iPhone retina display I traditionally use a resolution of 640×960. When designing for mobile or iPad in PS should I compensate for the hi res display or just design at the 320px (72 DPI)/768px (72 DPI)?

I am having problems understanding your approach to this. I have been working with a framework lately and working on a responsive grid system. Maybe I am understanding this differently but I set my responsive parts in a separate stylesheet to another stylesheet I call ‘global’ or ‘base’ where in this goes the main grid system. In this part of your script

you have 1824px which yes is understandable, very large screens, larger then my imac monitor so therefore the grid system can expand. But then you have 1224px, ok this is larger then the resolution of my macbook but 1200px at least is my imac size and to me the standard size of any screen round a bout.

Now I feel in my (round a bout) 1200px size monitor, these two sizes are gonna class. Why not delete (min-width : 1224px) and set it at a much larger pixel rate.

I hope this makes sense. Now here’s how i’ve done it which to me makes more sense. Now between 768px and 1824px I can then create the grid system as normal to whatever size i feel and when it goes below 768px or above 1824px, it changes. But their is no mixing.

we are planning a tablet version of our existing website with entirely different content. Now, just want to know the css media query for the same catering all the tablets i.e. android, ipads, noble nook,kindle etc.

You should use percent based values inside of the stylesheet, and set a max and min width for the link to the stylesheets. Everything should be fluid except of the breakpoints, but the viewport above 900/960px can have a fixed value.

Maybe i know what’s your issue, on iPhone when you switch from portrait to landscape there is a bug screwing user zoom, therefore it overflows (if i understand your problem correctly). If that’s the case, you have to zoom out to “manually fix it” isnt it?
There’s a nifty script here http://github.com/scottjehl/iOS-Orientationchange-Fix, that can fix it for the user automatically, and it works pretty well!

hei there i’ve been trying to do something to say sort of “for anything with device-pixel-ratio&gt1 use this” .
I’ve tried something with the not operator : @media not screen and (max-device-pixel-ratio: 1) { stuff }
Is it worth in your opinion?
Btw i was wondering if vendor prefixes are still needed for this or just the vanilla

All this pixel-fiddling does not make sense. With iPad 4 it is clear: you have to ask for the physical size and not for the pixel-resolution. even on a 640-pixel wide iPad a two column design of a web page does not make sense.

I now realized my responsive web page. See http://mm.ymir.de . It not only adapts to small devices, but also to small browser windows. So just narrow the width of your browser and look how the page changes. Also the pictures are responsive: When loading the page they are loaded according to your window size.

Have you tested which size (min-width/max-width) can target the new MacBook’s Retina display?
I’m not sure if this new high definition laptop screen resolution is conflicting with the above media query for “large screens” (min-width : 1824px).

Hey peops, just to let you know that if you’re using Less with the Less.app on Mac, it doesn’t accept the original ‘device-pixel-ratio’ of 1.5 or indeed the opera equivalent of 3/2.
All device-pixel-ratios need to be 2 only.
Just thought it might help someone out there!
Peas and korn.

Plus, Chris – what is your view on the HTML5 form validation strictness of the URL input type. I really have to include my http:// – really? What is up with that…

I used media query it works in browser when i re-sized my browser, but it not work with mobile device, ipad, android , android mobile screen size width 320px, but it takes @media only screen and (min-width:768px) and (max-width:1024px) this query , what i do?

Umm, what Marcy? Nobody validates HTML anymore? Looks like you may need to work in another field.

Google loves valid HTML, and so does it’s crawlers. If you don’t have valid HTML, you don’t have a site worthy of indexing. This is one thing that makes HTML 5 so great. It is semantic. Just because it works does not mean it’s working for you or your clients.

Look, I work in the industry and I’m speaking from my personal experience. I know web standards and I write code by hand every day. If I run into a problem I can’t spot easily, validation is one potential tool but no one at my agency validates as part of our regular workflow anymore. That’s just the way I see it.

f1ss1on: But what will your code do on a Samsung Galaxy 4 and an iPhone 5? Why do you ask for pixel size instead of physical sizes? It will only save your employment changing the same code again and again to add each new device.

Marcy also said that the page fold is a myth. Which is another case in which she is wrong. It has nothing to do with whether people know to scroll or not- it’s the notion of captivating your audience quickly. Putting the right content above the fold entices them to scroll in the first place.

What I don’t understand is your need to make insulting personal comments like this. Debating ideas is awesome – insulting somebody and questioning their right to practice a discipline is immature and unprofessional.

Page fold is not a digital term … it’s from the days when newspapers (remember them?) were sold on the corner and the publisher used the most exciting stories above ‘the fold’ of the paper to sell them. Print folks evolved into digital and carried terms that were not interchangeable … Browsers scroll, so there is no such thing as above or below the fold … I’ve seen many websites that only scroll left/right, so where is the fold on those? People interact with websites, that’s why we build them, so why should everything be above ‘the fold’? A waste of design ethics when one does that.

It is my opinion that misinformation passed around by people in my industry who claim to be experts is one of its biggest downsides. Especially when they present their opinions as fact, like Marcy did. Junior developers are led astray every day by comments from people like this.

Your responses are over dramatic. I did not personally attack Marcy; she tried to use her agency’s practices to qualify a misguided statement. I responded to it.

Hi all, becareful with Media Queries! They are not pixel accurate.
Some times they are off only 20 pixels but other time they are off up to 150 pixels… However, even few pixels is very bad when trying to target a certain mobile phone screen.

is not working when i test the site im working using ipadpeek. but works when i removed the “device-” is there any difference between them? thanks, this is my first time developing responsive website so im a little confused. please guide me.

Vhinmanansala, I am just reading Ethan Marcottes Responsive Web Design and he mentions that min-width and min-device -width are two different things. I guess the essence is that a screen is not considered a device.

It depends on your approach to code. Actually it really works fine without the term “and (orientation : portrait)” because in most devices it is the default view. But in some cases (there may be), when the device is kept horizontally, the CSS code should be changed. It depends on your design + the way of coding. Mostly if you use “Percentage values” for specifying width, margin as well as padding, the removed term is not needed. But if you mention the values in “PX” (Pixels), you have to use both “(orientation : portrait)” as well as “(orientation : landscape)” separately.

If anyone here needs a way to quickly generate valid custom media queries or need to look up other device specific presets, I wrote a free media query tool called Media Query Builder which you can find here -> Media Query Builder

I just found something strange that might save people a lot of wasted time with media queries on Android devices:

I’m developing a mobile site and for some reason, a 540×960 phone running Android Jellybean would only pick up the 360-459px wide stylesheet. When I commented out this stylesheet from the header, the phone totally ignored the others, even the one that specifically targets it’s resolution.

After a ton of research, it turns out that the default browser zoom setting does not actually zoom in the browser per se, but rather ignores it’s physical resolution, and pretends to have a smaller one. After some experiments:

‘Close’ zoom loads ‘small.css’,

‘Medium’ zoom loads ‘mid.css’ and

‘Far’ loads the proper stylesheet for the screen’s actual resolution.

It would appear there is no way to force the user’s browser to load the proper size stylesheet if their settings are different. Just thought I’d share this, it’s wasted a lot of my time, and finally I can move on :) Hope it helps

Hi again, here’s a few more things I’ve since learnt about the subtleties of Android devices:

There are several attributes that can be applied the the tag that alter the way they handle zoom. One of these is: content="target-densitydpi=device-dpi"

What this does is prevents the device from zooming on the page when it loads. This solved an irritating zoomed-on-load issue I suddenly had with the iPhone 4s. Users can still scale (if you’ve allowed it), it merely targets the device’s actual DPI rating, instead of relying on the often unpredictable automatic zoom. My meta tag now looks like this:

This allows for the layout to adjust completely based on any display. The only hitch is the OS. For some reason, I can’t for the life of me get it to load on a HTC 7 Trophy windows phone without being zoomed in. Any thoughts? This is the only OS that seems to cause problems now. Even Blackberries work fine.

In another tweak, I’ve updated my media queries in an attempt to ignore most tablets while still catering for ludicrously high-DPI phones, such as the HTC Droid DNA (1920×1080, wow). To do this, I’ve simply added another media query with a new condition below the main one:

This way, the phones load like normal, but any display larger than 960px must have a very high DPI display to access the styles, so hopefully this will be phones only. It’s not perfect, as I haven’t had a chance to try it on the Retina iPad (DPI anyone?), but it is designed to quickly provide a clear divide.

Rather than try and guess how high-res the next generation of phones will be, and have the site inevitably break on some new device in the future, I thought it made more sense to simply allow no limit and instead exclude the devices I didn’t want by using media queries. Having your mobile layout designed for small screens appear on a iPad makes you feel like a spoon-fed kid, as the buttons are now big enough to smash with your fists instead of point with a finger.

I found that some of the media queries here a bit haphazard. For example, the smartphone landscape query is min-width:321px my desktop browser when larger then 321px wide will run the stylesheet intended for smartphones. Seen how iOS+Safari doesn’t consider itself a handheld device, using @media handheld and (... does not work, so I found that some were clashing with others were they shouldn’t have been. After many frustrating hours I went looking and found this question on Stack Overflow, Media query ipad vs iphone4

The media queries are being used to specifically target a device width, pixel density(css ratio) and the orientation. Leaving very little for one device to use another stylesheet not intended for it. Although this maybe slightly more to write out, you get the consistency across all devices and I have never had any headaches using this method since.

I am pretty new with media queries. I have a website I am creating a mobile version for. When I check the site in iphone 4s portrait, 320px wouldn’t cover 100% the width. I need to push it to 375px to make it cover the width of portrait view. Any suggestions?

I have tried the same media queries for wordpress test site loaded on localhost. I used online responsive design tool http://ipadpeek.com/ . This tool fails to catch landscape and portrait mode queries. But while I tested localhosted wordpress site directly by changing screen resolution of my pc with windows 7 in portrait and landscape its works.

I know article is from a while back, but has anyone had an issue with “max-device-width” and having rendering issue.
My impression was that the “max-device-width” only rendered on phones, tablets, and mobile devices, not on desktop browsers.
This happens when the browser is set and the initial load of the css file with the @Media query loads.
So if I have

the desktop browser or screen resolution of the desktop is set at 1280px, it will actually render the 1280px styles mobile styles and not the desktop styles. Did browser makers roll “max-device-width” into their browser builds? Any pointers or insite would be great.

I have built my first truely responsive site, with a lot of help from CSS Tricks. I built it in SCSS with lots of media queries using breakpoints as outlined by Chris C. My question is- I have only user min-width and max-width (No min-device-width or max-device-width). Is this incorrect? As far as I can tell my site is working fine across all devices, though testing UserAgents is a pain. Most of my testing comes from resizing the browser in Chrome, IE and FF, and then using Chrome Dev Tools to test on Galaxy Nexus and also on my wife’s iPhone. Here is an example of my breakpoints.

Martin- Sure! With the above code, I can use SCSS and mixins to easily make my site mobile responsive. Rather than creating a huge block of CSS at the bottom of my stylesheets and putting all my mobile CSS there, I add in my mobile CSS as I design my normal CSS. I then use a gem which moves everything to the end for production. Moving forward with the above breakpoints, my CSS might like like this:

My above illustrations was simple… but when you use this for an entire site it becomes super powerful. When I need to go back and edit the screen width of one div only on mobile devices at 640px, I simply go to that class in my CSS and make changes- I don’t need to scroll through a page of mobile CSS to make changes.

As Chris Coyer said the above way(using mixins and SCSS) is the way your brain wants to connect the dots, so why organize things differently. Since I have started to do this, I can just code mobile as I go. I can put together a sites CSS and responsive all at once, rather than two separate items.

Hi Chris. Great article. I often refer back to it. I was just thinking that a lot has evolved and come about with mobiles and tablets since you wrote this article back in October 2010. Smaller tablets have been released and some mobile resolutions have gotten bigger. Has this blurred the lines somewhat with your advised media queries for different devices? Or would you say it’s largely unchanged?

I have a website Noobpost I’m trying to figure out how many media queries max-width sizes I should use, right now I have four, but it doesn’t seem to work well with landscape views. It also appears I need to position everything in a percentage to make it more fluid.

You could always just keep the content centered (or left aligned) on the page at a normal width, say 960 or 1024px which would allow it to be readable. To fill up the extra space on the sides you could use a gradient, clever shadows, or some images to “fill” up the blank space. My site maxes out at 960px so it looks the same on 1600 wide monitors, and 1900 wide monitors and beyond. A word of advice- when designing for large screen, testing or actually designing for a large screen is really helpful- it is hard to visualize a large screen when working on a 13″ laptop.

Hi, I have some question, in ipad protrait mode…
you have specified the min-device-width:768px and max-device-width:1024px and orientation portrait and the same values you given for landscape too. Actually, when viewing with portrait in ipad the max-device-width will be 768px right? How the max-device-width be 1024px.

This is an informative article however i would approach responsive design much the same as we currently do for fully fluid layouts. My personal approach is semi fluid in nature with responsive design only to enhance the content.

If for example we apply a fixed width on the container (div as the most semantic selector) Then we can simply target that by simply applying a max width, minimum width and auto for backwards compatibility. Of course will work for semi modern browsers this is the best option in my opinion. We can scale this up or down based upon a percentage and change the width constrictions and there we have a complete fluid and responsive design.

Of course other elements needs to be specifically styled, rearranged or sometimes hidden (i would not recommend) by using media queries.

ok, just ignore my comment above about swapping the media queries around. I have just noticed a missing } which was causing the styles that followed the missing } not to work. Doh! Should have seen that one!

hi , iI have just tried this snippet some how it is not working for me. It doesn’t set the right CSS based on device or when i resize the screen in my browser. So below is what works s fine for me. It allows me to apply css on both Phones and desktop with small / resized screen size

`@media only screen and (max-width: 480px), only screen and (max-device-width:480px) {}//for mobile phones
@media only screen and (max-width: 768px), only screen and (max-device-width:768px) {}//for tablet with medium screen
@media only screen and (max-width: 960px), only screen and (max-device-width:960px) {}//for tablet with large screen`

I know this is perhaps not the answer you were looking for, but why do you need device-width? Do you have a specific reason for using it? I normally build my sites using Min/Max width which I code in using SASS breakpoints, and when I go to production I leave them be. The only way in which I could see myself using a device-width tag would be for some sort of mobile app based on HTML.

With Min/Max width, you are also allowing for new devices as they emerge, no matter what the device dimensions are. I like to develop for all sizes- meaning that as I use breakpoints I want my sites to look 99-100% at every width, even if it is in between normal device widths. With Min/Max width you can test this by dragging your browser around.

In other words- unless you can name a reason to use device width, stick to Min/Max width.

Hi Patrick and Frank– given the evolving nature of mobile platforms, fixed widths are less flexible than percentage settings- so describing a set dimension now may well compromise A N Other platform in the future. And make more work for you.

While previously I’ve tweaked ready-made solutions for responsive web apps, 2013/2014 are for me, professionally, the years of building responsive markup from the ground up for SharePoint 2010 and 2013. I’ve used these @media queries with great results. They work on nearly ANY mobile device, provided the device’s viewport resolution fits these parameters. Using these queries you can hide/display content containers (div’s and whatnot) to create distinctive experiences for your users, based upon the device they use to access your web app.

I’m VERY impressed with this site’s responsive design, not just how the content changes widths but the attention you guys have paid to EVERY piece of the UI, especially the nav and the banner ad. Really impressive, CSS-Tricks, I’m subscribing and look forward to gleaning a lot. Great job.

So what about new bigger smartphones, do we still use max-width: 480px? But their resolution is much bigger now, with iphone 4S having 960px and latest Nexus much higher – does it mean on those devizes users will see desktop version of the site? I’m a bit confused

If you use min-device-width or max-device-width, make sure you are also defining min-width and max-width (same goes if you’re targeting height, and yes people targeting heights does work).

Also at the very minimum use this in your head section but preferably use this

If you use only @media only screen and (min-width: NNNpx) and no max, expect troubles but they are solvable … try to break your code to what is the architecture (dimensions and sizes) and what is design (colors and imagery) and have separate files … Architecture files should have min/max defining start and stop points, while min- can carry design element transformations upward (or downward depending on if you start mobile first or not).

If you use min-device-width or max-device-width, make sure you are also defining min-width and max-width (same goes if you’re targeting height, and yes people targeting heights does work).

Also at the very minimum use this in your head section but preferably use this

If you use only @media only screen and (min-width: NNNpx) and no max, expect troubles but they are solvable … try to break your code to what is the architecture (dimensions and sizes) and what is design (colors and imagery) and have separate files … Architecture files should have min/max defining start and stop points, while min- can carry design element transformations upward (or downward depending on if you start mobile first or not).

Also at the very minimum use this in your head section <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> but preferably use this <meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no, target-densitydpi=device-dpi”>

hello, my website isnt responsive. i am using joomla 3.3.0, how can i make this responsive, which when open in a mobile device it will fit on its screen size and not changing or shuffling any images, it should be look like exactly as it is in the desktop browser. can anyone help me?

It’s important to remember that max-width and min-width include the pixel referenced. For example, min-width: 768px includes the 768px position, the same occurs with max-width: 768px. It’s used twice and we have less control. On these cases, it’s better to add one pixel more to the min-width; for example, min-width: 769px.

Yes this is critical if you are showing and hiding certain elements using css. I would not use “-device-” or when you resize the browser it will look horrible. Just an FYI. I never use “-device-“, I don’t see the point because all devices will fall into the above @media queries that Gerard posted. Keep these on file and thanks for sharing.

Hi… Do you have this posted somewhere online where I can bookmark it to find fast please?? I am looking for an online guide that I can use for reference for current and future projects as it appears that this one is out dated. Thanks in advance for your reply.

I’m wondering why so many different pixel-sets of different media-querys exists to somehow cover every potential screen resolution. What will happen if in maybe one year a complete different resolution will be required because of new hardware? Isn’t there a way to be more flexible and to work with proportions of a screen based on the actual font-size… e.g. with the attribute “em” ?

I’m using @media only screen and (max-width: 768px) etc. in my css file, but I want images in my main html pages to show or not show depending on the screen size. How do I control that? Have you done that before? I just want to pop in a different image if screen size is smaller than the 1024px.

my problem is that when i use @media (max-width: 320px) then page works fine . but below that . when i write code for @media (max-width: 800px) then 320 does not work just @media (max-width: 800px) works fine ,,,,in short both doesnot work at the same time
anyone can answer ?
will wait :)

How do responsive design code writers address phones that have more pixels wide than the old phones did. For instance, my cell phone (ZTE Warp Sync) has dimenions of 1280 x 720 pixels (not the tiny 340px Ive been seeing in tutorials and sample codes) with a pixel density of 293.72. 1280 (landscape) nor 720 (portrait) is considered phone size any of the media queries I’ve been seeing. Some of this code would render a site I make like a desktop, rather than a phone unless I’m missing something.

I am liking this approach – thanks.
Question: If I put absolutely everything in ems (ie all elements, text, etc) and the layout in % (or should this also be ems?)- can you share a simple suggestion for the minimum number of media queries to use and the em values.

This is only an example. My problem is that when i write an other alternative stylesheet with the same code like i wrote in this comment, the stylesheets don’t overwrite the others when I change the browser-width oder -height. Is this the mistake: …(min-width: 0px, max-width: 800px)” ?
Must i write the code like this: …(min-width: 0px) and (max-width: 800px) ?
Hope my english is good enough to understand me.
I would be lucky about an answer.
Thank you

HI i am using (landscape and portrait) for screen size (1024×768). But again when i am using this method for screen size (736×414) then it’s not workign. Any Suggestion ? and also plz tell me that is this method can see in desktop browser?

I am using the Responsive Theme. What if I want to hide my sub-menu items on the desktop, but show them on the mobile? I use the “Responsive Menu” plugin for mobile, which provides a nice slider expand/collapse look for menus there. But, on the desktop I don’t want sub-menus to show. The main menu items (e.g., About) will take you to that section/page of the website, where a sidebar navigation will then be used from that point on for all the associated pages.

Is it possible to target individual screen sizes instead of using min-width and max-width etc…

I would like to start on the laptop sizes:

1024 x 768

up to

1920 x 1080

Then eventually work into mobile devices, but I found it particularly difficult to target that way. I have tried lots of ways but it just seems that if I use min-width, max-width for example, I usually end up changing the styles for several resolutions with only one media query. Any solutions to this? I know a lot of you go through this (when starting out), but what have you done to resolve this issue? Any tips and/or suggestions?

I have two div containers for food menu items. One is called menu-container and is a class the other is mobile-menu and is an id. I want to show just .menu-container on the desktop and just #mobile-menu on phone and tablet. I have the max-width set to 1047 and the min-width 1048. When I view it mobile everything looks and works great but when I view it on the desktop both menus show.

This has been driving me crazy and I am not sure how to resolve this issue.

These media queries don’t seem to work on iOS 8.3 (haven’t tested older OSes). Unless I’m missing something. For example here’s a simple test. For iPhone4/4s the background should be red. For anything larger it should be blue.

But it ends up being red for iPhone5/5s, iPhone6, iPhone6Plus. It’s blue for iPadAir, iPad Retina, Desktop.

I wrote the 4 standard media queries with bootstrap.It is ok.
But it is not ok in pixels between the media queries because I used padding or margin.
How I can solve this problem and are many other media queries?

Is it possible to target a particular screen width AND HEIGHT? For instance, we’ve developed a touch screen kiosk/web app that’s nothing more than a responsive website tailored to a specific touchscreen monitor width and the usual mobile sizes. The issue comes in the “bleed-over” of target sizes via min- and max-widths causing a layout fix on the touchscreen to break the layout on mobile devices. If there’s a way to target a specific width WITH a specific height, that might fix our issue.

It seems like the best idea is to choose the widest portrait of the cell phones and simply make ALL portrait-size mobile device design start at that size. Rather than collapsing columns and stuff at 480px, you’ll do it at 736px width instead because of of the iPhone 6.

That’s the simplest.

But, isn’t there something much simpler that Zurb Foundation is doing? And what about device-aspect-ratio instead of pixels?

Man, I’m having trouble with this media query stuff. I followed a tutorial on how to build a navigation bar. I built my navigation bar off the tutorial. It’s a bit different. I just took the basic idea from the tutorial. Anyway, this is my problem, when the screen is smaller, the nav bar changes. You can click the nav bar. It opens up a vertical navigation bar (I call this a mini-menu). While the mini-menu is open, if you resize the browser and make it larger than 840 pixels, the old navigation bar is misplaced. You can see what I’m talking about at my site. http://JetBBS.com/test2.html. Do you have any ideas how I can fix this? I’ve tried just about everything I could think of! I think I need to do something in the jQuery code (http://JetBBS.com/js/click.js) but I’m not sure what. jQuery isn’t my strong suit. Thanks!

I think what the developer was showing was the media queries for the various iPhone stuff. Yeah, it’d work with other devices, but it definitely works with the iPhone 4 and 4S. I do believe that’s why he’s grouped it under the iPhones section. They’re basically saying hey, this is the media query for iPhone 4 and 4S. Other phones that use the same resolution will be included as well, but if you’re looking for the code to support iPhone 4 and 4S, here ya go.

For iphone 4 and 4s, device-width would probably be 480px in landscape mode — but only if these two devices were Android phones.

Device-width works differently on IOS and Android. For Android it’s (usually/not allways) two (2) device-width. One for the short side in portrait orientation and the other for the long side in landscape mode.

However, in IOS there is only one (1) device-width. It’s the shorter side, no matter what orientation. So actually, for the iphone 4 and 4s the device-width is 320px — even in landscape orientation.

Another problem is that different browsers respond differently to device-width. Example: The Android default browser and Dolphin (but not Chrome, Opera, Firefox) use physical values not CSS pixels which is the norm.

All this together means that using device-width for the page layout is not very far from using random numbers :|

I’m not a developer at all but trying – thank you to everyone who’s posted here. It’s helped me. Can anyone tell me what I have two ads returned in this code? Or how I need to correct it? Very grateful.

I think this is the better way to post my previous question. Apologies.
I’m not a developer at all but trying – thank you to everyone who’s posted here. It’s helped me. Can anyone tell me what I have two ads returned in this code? Or how I need to correct it? Very grateful. You an see the code here:

If any one have doubts and window’s sizes etc… Place this JavaScript alert to kwon all informations about window sizes(width and height) and device pixel ratio to help to develop better your mediaqueries. Thank You

I just want to know how to set up media queries to work with the majority of devices. Device-specific is not the route I’d like to go because there are an insane amount of devices, but I still want to know the basic media query breakpoints that I should use and best practices for doing so. Any tips?

This is very cool how you list every single devices. While is it very useful, it can be very daunting and overwhelming.
I usually use 4 ranges for my site that it….
1)smallest for wearable,
2)smaller for mobile phone,
3)medium for the tablet, and
4)large to max for laptop and desktop.

Thank you again for the detailed list. That is a lot of work and I bow to you sir. Thank you again for awesome works on this site. I learned a lot from this site.

It seems like all you really have to do now is design your website to break wherever it looks good using a desktop computer and Chrome web inspector tools.

Whatever the heck happens with retina and other high pixel density displays doesn’t seem to matter since apparently they make their higher amount of pixels display as if it’s the same amount of pixels as a regular display.

Based on this, 768px still seems a reasonable breakpoint for tablets and 480px and 320px seems to be a reasonable breakpoint for phones. Whether those dimensions are actually 1.5x, 2x, 3x or higher on retina-like displays doesn’t seem to matter as far as media queries are concerned.

Personal opinion here of course, but your website really shouldn’t care what device it is running on. CSS media queries should be used to adjust the website layout, and possibly visual style, to provide the best user experience possible for the device screen resolution (viewport size). Break points, if that’s your thing, can be determined based on the height of the viewport at runtime (100% HTML element height, or a calc() derived from it, etc).

If you really need to provide device-specific content, using JavaScript or a server-side script to query the user agent string is one solution, but it isn’t super reliable due to the fact the user agent string can be easily changed.

I am using LESS, and I want to know how I can combine media queries into a variable to create a general “mobile” media query (ranging from the smallest popular viewport on the market to the largest popular viewport size on the market)? Any ideas?

I recently started a blog. I do not have good knowledge of CSS. Which is why the speed of my website is very slow. Suggest me so that my website’s speed is up and Google starts searching. Provide CSS code for mobile, tablet, desktop, and laptop. I sincerely hope you will help me.
please help

Sounds like you could use some advice. The snippets in this post will help you adjust layouts for specific devices, but speed will ultimately depend on the CSS you write, the complexity of the design and lots of other factors. If you have specific questions, please post them in our forums — lots of great help comes out of there. :)

I see this was last updated October 9, 2017. Sorry to be greedy, but do you have an update to include Samsung Galaxy S7 and S8?
I too am just getting started with this part of responsive design (I already use flex layout and rem units). I greatly appreciate this page and it’s device-specific content. For me, it’s like a holstered sidearm as I walk into this minefield of devices. I hope I never have to use it, but I’m glad it’s there.
It’s also a good way to understand popular devices and to then lump them into groups via more generalized media queries. It’s useful data.

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.