Skip to content

Viewport vs Screen Resolution vs Device Pixel Ratio

By Pritesh Ranoliya · Updated

The viewport is the size a web page is laid out at, measured in CSS pixels. The screen resolution is how many physical pixels the display has. The device pixel ratio (DPR) is how many physical pixels draw one CSS pixel. On an iPhone 16, a 393×852 CSS pixel viewport at a DPR of 3 fills a 1179×2556 pixel screen.

CSS pixels: what your layout sees

Media queries, width: 100vw, window.innerWidth and every length in your stylesheet use CSS pixels. A CSS pixel is a unit of length, not a dot on the glass: browsers scale it so text stays readable at a normal viewing distance. That is why a phone with a very sharp screen still reports a narrow viewport around 360 to 440 pixels wide.

When you write @media (max-width: 430px), you are asking about CSS pixels, and that is the number in our screen size lists.

Device pixels: what the screen has

The screen resolution in a spec sheet counts physical pixels. Phones pack two to four physical pixels into each CSS pixel in each direction, so images and text look sharp. You almost never size layouts in device pixels.

window.devicePixelRatio returns the ratio of physical pixels to CSS pixels (MDN). Multiply the viewport by it and you get the screen size:

Device Viewport (CSS px) DPR Screen (physical px)
iPhone 16 393×852 3 1179×2556
iPhone SE (3rd gen) 375×667 2 750×1334
Galaxy S24 360×780 3 1080×2340
iPad Air 11-inch 820×1180 2 1640×2360

Some Android phones use fractional ratios such as 2.625, so the product is only approximately the panel’s resolution.

Why phones need the viewport meta tag

Without <meta name="viewport" content="width=device-width, initial-scale=1">, mobile browsers lay pages out at a wide virtual viewport (often 980 CSS pixels) and shrink them to fit, so text is tiny (MDN). With it, the layout viewport matches the device’s CSS width and your media queries behave as expected.

Where the pixel ratio matters

  • Images: serve 2× or 3× versions with srcset so photos stay sharp on high-DPR screens (web.dev).
  • Canvas: scale a <canvas> backing store by devicePixelRatio or drawings look blurry.
  • Hairlines: a 1px border is one CSS pixel, which is three physical pixels wide at DPR 3.

Test layouts at real viewports

Because layout depends on the CSS viewport, test at the widths your visitors actually have. The Mobile Simulator renders your page at each device preset’s CSS viewport, and the screen size lists show the most common widths.