Last Updated: September 29, 2021
· elad2412

How to get real Mobile CSS resolutions for Responsive Design

At this time, mobile devices have improved so much that their screen resolutions are similar and sometimes even better than desktop screens resolutions.

For example Galaxy S4 of Samsung has 1080X1920 pixels - Full HD screen!

But in responsive design we check resolution and need to fit according the resolution and if you try to add media query, let's say min-width of 1000px and check it on the Samsung Galaxy S4 you will see that nothing happened.

The reason for it is that mobile high density screen have two aspect of pixels.

Real resolution<br>
The first resolution is the factory real resolution, it's mostly for videos and images. on Samsung galaxy S4 the real resolution is 1080X1920.

CSS resolution<br>
The second resolution is for the browser. and for us developers that means we need to act different and not according the real screen resolution. in Samsung Galaxy S4, CSS resolution is 360X640.

Samsung Galaxy S4 resolution:<br>
Real resolution: 1080X1920<br>
CSS resolution: 360X640<br>

How to acquire CSS resolution?
In Wikipedia you have all mobile devices resolution table (tablet and mobile devices).



The calculation is very easy, you just need to divide the pixel screen in the CSS pixel ratio number, like this:
1080/3 = 360px (portrait - width)
1920/3 - 640px (portrait - height)

That's it! We have the CSS resolution of Samsung Galaxy S4 - 360X640 pixels.


If you like this tip, I will be happy to get your LIKE. You can follow me and endorse my skills.

9 Responses
Add your response

@barnettjw , its nice, but the issue is for device you dont have :-)

over 1 year ago ·

I also have a list of 195 devices and their viewport sizes here:

I've been regularly going "viewport shopping" to use devices in store and test their viewports. I'll be adding some of the ones from the Wiki entry too, now.

Note, that the Nexus 7 calculation in the Wiki page is slightly wrong. They changed the pixel ratio in Jellybean to make the portrait width 600px instead of 603px, presumably because developers might use a generic 600px media query.

over 1 year ago ·

Thnx a lot Elad.
I've implemented in my website and now i want to calculate the pixels as you mentioned in this article.
I do understand the issue, but can you guide me where technically I have to add it in my CSS file?
Many thanks!

over 1 year ago ·

@shuraki, this protip just say how your mobile react to the responsive breakpoints.

There is nothing to add to your CSS.

Now, if you want you can add support for retina screen according to the pixel density of screens or with Responsive breakpoints that recognize your screen density.
or you can use SVG images that are appropriate for all screens.

like this Example(breakpoint for high density screen):
(-webkit-min-device-pixel-ratio : 2)


SVG Support to your project

over 1 year ago ·

Many Thanks!!

over 1 year ago ·

That was very helpful.. thanks! :)

over 1 year ago ·

This is absolutely absurd. Why keep a list of devices that's going to change in the future? Browser makers need to give us the screen's hardware pixel density. With that we can display anything we want.

over 1 year ago ·

that's very clear and helpful. thanks

over 1 year ago ·