
Brandon T. answered 05/26/19
Experienced Computer Science Tutor
That's a Good Question,
From my experience it is still better to use pixels that it would be to use a unit of measurement like CMs or INs.
Different devices have screens that have different max pixel counts. While I agree that many devices these days have a similar resolution to each other in pixel count, there still exist some devices that have specs that are slightly different from others. What I'm trying to get at is this: Something that is 2cms away from the left of the screen on desktop may very well only be 1cm or less from the left of the screen when you switch to mobile.
Different devices offer a different level of real estate to work with and if you tried to fit all of your content into the same physical dimensions on all devices (while I'm sure it could be done eventually) is not best practice. It is easier for a programmer to use 20px from the left than to try to convert in their head 1cm to pixels and then hope that pixel equivalent of 1cm on one device equals the same on another.
Logically, one would not immediately assume that physical units of measurement would be a problem - but it's sort of an anti-pattern that would go against best practices. In practice, even different browsers translate pixel width differently from each other. This would mean on the same computer screen you could have different pixel values based on the browser you use. To have to conform to a physical unit of measurement would take far more work and create more problems than it is worth.
In conclusion, it is not a good idea and it's not as simple as predicting the physical width of a device that exists in physical space.
Hope I've helped clear that up a bit :)
Best,
Brandon T.