I'm new to responsive css. I've learnt a lot about media queries, but I still have not figured out which is the best way to catch if the user is using a mobile or not. The media query to identify a mobile user uses the device-width, but which is the best value to set the breakpoint? When using my android smartphone with Google chrome, the width of the page is about 400px, even thought the real resolution is full hd, 1080px width. Does this depends form the browser, or what? I saw that someone uses the em mesure to set the breakpoint, is this more accurate? I'd like to know about the handheld property more, too. Finally, after having read lots of different informations, can you please tell me which is the moste effective way, the best media query to catch if the client is mobile or not? Thank you.
-
use jquery or javscript to detect if a user uses a mobile device, the method are done by detecting device browser user agent. media query only fetch designs based on device width and device width varies. – Allan Empalmado Jun 30 '16 at 16:32
-
@Allan I want to desing a responsive website, so css is the main thing chainging from desktop to mobile. Css can be changed through JavaScript, but I don't think it's the proper way to make the design responsive... – Franz Tesca Jun 30 '16 at 16:56
-
Possible duplicate of [Media Queries: How to target desktop, tablet and mobile?](http://stackoverflow.com/questions/6370690/media-queries-how-to-target-desktop-tablet-and-mobile) – showdev Jun 30 '16 at 17:04
1 Answers
The media query to identify a mobile user uses the device-width, but which is the best value to set the breakpoint?
There are a few theories out there on how to handle this. Some people go and find the most popular device widths and set their breakpoints at those places. This is great if you know for certain what most users on your site use. However, the downsides are that you have to mold your design to those widths and you have to continually update your code as new devices come out.
So your breakpoints would be something like:
// iPhone 6
@media only screen and (min-device-width : 375px) {
// styles go here
}
// iPhone 6+
@media only screen and (min-device-width : 414px) {
// styles go here
}
The other theory is to make it fully scalable at any size regardless of what the device is. The upside to this is that you can insure that your design looks great on all devices. The downside is that it makes your code a bit more bloated. the breakpoints here would be wherever you need them. I personally use this method but start with break points at 1200 and go to 1100, 1000, as needed. If I'm going mobile first I'll start with 320, 350, 400, 500, etc...
When using my android smartphone with Google chrome, the width of the page is about 400px, even thought the real resolution is full hd, 1080px width. Does this depends form the browser, or what?
The device width has many factors to it. But the device width is basically the number of pixels across that the browser is displaying. There's a little more to it than this, but your best bet is to Google device widths.
I saw that someone uses the em mesure to set the breakpoint, is this more accurate?
Nope. It's just a way of subdividing from a parent element. Until you have more time to research this, stick with pixels.
Finally, after having read lots of different informations, can you please tell me which is the moste effective way, the best media query to catch if the client is mobile or not? Thank you.
The best way to do this is to determine your break points. You cannot target mobile browsers specifically using CSS. You can only target the attributes of those browsers (width, height, orientation) so you can know that iPhone6's are 375 pixels across in portrait. So you can target them using that width. As Allan said, you can target devices with Javascript or server side libraries and add classes that way. But IMO it's better to stick with device widths and save those for situations where you're absolutely stuck.

- 174
- 2
- 11
-
Thank you very much for your answer. Last question, which width would you recommend as breakpoint for mobile/non-mobile css? Do you think 480px is good? – Franz Tesca Jun 30 '16 at 18:43
-
You're going to need many breakpoints. Smaller computers start at 1round 1100, tablets are around 800, and phones are around 500. – Michael Heath Jul 01 '16 at 19:11
-
I know it's bad practice to share links on Stack, but start here: http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml and then look around some more on Google. If you have any analytics on your site or demo see what devices they use most. Or go with option number 2 above and make the entire design responsive. – Michael Heath Jul 01 '16 at 19:13