Menu

CSS Pixels vs Device Pixels: Why "It Looks Fine on My Monitor" Is a Bug Report
πŸ“°

CSS Pixels vs Device Pixels: Why "It Looks Fine on My Monitor" Is a Bug Report

DEV Community: rΒ·David BrooksΒ·9 days ago
#vAcX3d0i
#devtor#devto#dev#viewport#scaling
Reading 0:00
15s threshold

Most layout bugs are not bugs. They're mismatches between the viewport we designed on and the viewport someone else is using.

Here's the thing that trips people up: a phone can report a 412 CSS-pixel-wide screen while being physically half the size of your laptop , and a 4K monitor at 200% scaling gives you exactly the same usable width as a 1080p one. Resolution and viewport are not the same number, and treating them as one is where "it works on my machine" comes from.

Three numbers that get confused

Number What it really means Where you see it

Physical resolution Actual pixel count of the panel, e.g. 3840Γ—2160 Product specs, OS display settings

CSS viewport width What window.innerWidth reports after scaling and zoom DevTools device mode, media queries

Device pixel ratio Physical pixels per CSS pixel (1, 1.25, 1.5, 2, 3) window.devicePixelRatio

A 27" 1440p monitor at 100% gives you roughly 2560 CSS pixels to play with. A 15" laptop at 1920Γ—1080 and 150% scaling gets 1280.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.