2

When I presume that a css media query with max-width: 768px can make my web page responsive to fit a mobile device. However, iPhone X and later still load the desktop version, because recent phones have even higher resolution than an old desktop.

How do I detect a mobile device not relying on the screen resolution, with Vanilla javascript, pure HTML and CSS?

romellem
  • 5,792
  • 1
  • 32
  • 64
Coalabear
  • 369
  • 1
  • 3
  • 5
  • 2
    Does this answer your question? [Detecting a mobile browser](https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser) – romellem Feb 18 '21 at 21:32
  • Did you forget to set the viewport settings? https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag – Quentin Feb 18 '21 at 21:33

1 Answers1

0

Pixels don't actually work based on the real density of the screen. The pixels we use are Density independance and the get scalated depending on the screen. If you follow up the media query Bootstrap uses you can see they actually set it as max-width: 575.98px for mobile devices.

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }

// Small devices (landscape phones, less than 768px)
@media (max-width: 767.98px) { ... }

// Medium devices (tablets, less than 992px)
@media (max-width: 991.98px) { ... }

// Large devices (desktops, less than 1200px)
@media (max-width: 1199.98px) { ... }
cicb
  • 94
  • 9