Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0 ๐Ÿ“– 4 min read

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

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

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). It still does not tell JavaScript the physical diagonal size of the monitor or phone glass in inches!

Browsers deliberately omit raw physical display dimensions (EDID data) to reduce browser fingerprinting. As a result:

Display CSS 1in Real Physical Size of 96 CSS px Error
Standard 24" 1080p Monitor 96px ~1.04 in +4%
13.3" MacBook Retina (2x) 96px ~0.84 in -16%
6.5" Smartphone (3x) 96px ~0.66 in -34%

So if you build a browser ruler using static CSS cm or in units, it will be visibly wrong on almost every laptop and smartphone.

The Reliable Fix: ISO/IEC 7810 ID-1 Credit-Card Calibration

Almost every person on Earth has a globally standardized physical reference object in their wallet: a standard bank card, debit card, or ID card.

Under the ISO/IEC 7810 ID-1 international standard, every standard payment card has the exact same physical width:

  • Width: 85.60 mm (8.56 cm / 3.370 inches)
  • Height: 53.98 mm (5.398 cm / 2.125 inches)

Instead of guessing the user's screen PPI, let the user hold a bank card flat against the screen and drag a slider until an on-screen card box matches the physical card edge-to-edge.

Once cardWidthPx matches 3.37 physical inches, calculating the exact effective CSS Pixels Per Inch (PPI) takes one line of math:

const STANDARD_CARD_INCHES = 3.37; // 85.60 mm (ISO/IEC 7810 ID-1)

export function calculateEffectivePpi(cardWidthPx: number): number {
  return cardWidthPx / STANDARD_CARD_INCHES;
}

From that single calibrated ppi number, every physical unit becomes exact on that display:

export function pxToPhysical(px: number, ppi: number) {
  const inches = px / ppi;
  return {
    inches: Number(inches.toFixed(2)),
    cm: Number((inches * 2.54).toFixed(2)),
    mm: Number((inches * 25.4).toFixed(1)),
  };
}

Persist that calibrated ppi in localStorage, and the user only ever has to calibrate once per device:

const STORAGE_KEY = "omnitools_ruler_ppi";

export function loadSavedPpi(): number {
  try {
    const saved = localStorage.getItem(STORAGE_KEY);
    const parsed = saved ? parseFloat(saved) : NaN;
    return Number.isFinite(parsed) && parsed >= 40 && parsed <= 300 ? parsed : 96;
  } catch {
    return 96;
  }
}

(Clamping between 40 and 300 prevents corrupted storage values from breaking the UI.)

Bonus Use Case: An On-Screen Ring Size Finder (US, UK, and India Sizes)

Once you know the true ppi of a screen, you can measure more than straight lines. You can render a calibrated circle where the user places an existing ring directly onto their phone or laptop glass and adjusts the circle diameter until it aligns with the inside edge of the ring:

interface RingSizeEntry {
  mm: number;
  us: string;
  uk: string;
  india: string;
}

const RING_SIZES: RingSizeEntry[] = [
  { mm: 14.9, us: "4", uk: "H", india: "8" },
  { mm: 15.7, us: "5", uk: "J 1/2", india: "10" },
  { mm: 16.5, us: "6", uk: "M", india: "12" },
  { mm: 17.3, us: "7", uk: "O", india: "14" },
  { mm: 18.2, us: "8", uk: "Q", india: "17" },
  { mm: 19.0, us: "9", uk: "S", india: "19" },
  { mm: 19.8, us: "10", uk: "T 1/2", india: "22" },
  { mm: 20.6, us: "11", uk: "V 1/2", india: "25" },
];

export function matchRingSize(diameterPx: number, ppi: number) {
  const diameterMm = (diameterPx / ppi) * 25.4;
  const closest = RING_SIZES.reduce((prev, curr) =>
    Math.abs(curr.mm - diameterMm) < Math.abs(prev.mm - diameterMm) ? curr : prev
  );
  return { diameterMm: Number(diameterMm.toFixed(1)), closest };
}

3 Frontend Edge Cases to Watch Out For

  1. Browser Zoom (Ctrl + / Ctrl -): Remind users to keep browser zoom at 100% during calibration and measurement, because zooming scales CSS pixels without changing localStorage.
  2. Prevent Accidental Text Selection While Dragging Markers: Add select-none (user-select: none) and touch-action: none on draggable measurement handles so mobile Safari/Chrome does not scroll the viewport while dragging a marker.
  3. Sub-Pixel Rendering for 1mm Ticks: On standard displays, 1mm is roughly 3.78px. Always compute tick positions from mm * (ppi / 25.4) instead of rounding each step cumulatively, otherwise rounding drift compounds to 2-3mm across a 15cm ruler!

Try the Live Browser Implementation

We built this full calibrated ruler, dual red/blue measurement markers (horizontal and vertical), and US/UK/India ring sizer completely client-side with zero tracking or app downloads:

Have you ever run into CSS physical-unit bugs on HiDPI screens or print stylesheets? Drop your experience in the comments!

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.