Menu

Why CSS 1in = 96px Is Not 1 Physical Inch (Building a True 1:1 Screen Ruler in React)
📰

Why CSS 1in = 96px Is Not 1 Physical Inch (Building a True 1:1 Screen Ruler in React)

DEV Community: react·Omni Tools·9 days ago
#bSQbqfrN
#devtoreact#devto#dev#physical#number
Long article (1114 words) — no AI summary yet.
Reading 0:00
15s threshold

If you have ever tried setting width: 1in; or width: 10cm; in CSS and held a physical ruler up to your monitor, you probably noticed something frustrating: it is almost never 1 physical inch.

On a 27-inch 4K monitor, a 13-inch MacBook Air, and a 6.7-inch Android phone, 1in in CSS can be off by 15% to 45% .

Here is why browsers cannot reliably report physical millimeters out of the box, and how we built a true 1:1 actual-size online ruler and ring sizer in React using ISO/IEC 7810 ID-1 credit-card PPI calibration .

Why 1in , 1cm , and window.devicePixelRatio Cannot Give True Physical Size

According to the W3C CSS Values and Units specification, 1in is locked to exactly 96 CSS pixels ( 1cm = 37.795px , 1mm = 3.7795px ).

Wait - what about window.devicePixelRatio ?

devicePixelRatio only tells you how many hardware pixels map to 1 CSS pixel (for example, 2 on Retina displays or 2.75 on high-DPI phones).…

Continue reading — create a free account

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