I built Check My Ring Size, a free tool where you hold a ring up to your screen and match it to a circle. It sounds like a weekend project. The hard part is one sentence: a web page has no way to ask how big a millimeter is.
If a circle is drawn 104 pixels wide, nothing in the browser tells you whether that is 17 mm on someone's phone or 30 mm on an old monitor. A ring that is 17.3 mm across (a US size 7) has to be drawn at exactly the right size, or the whole tool is worthless. This post is about how I solved that, and the bug that made my first version wrong by a factor of two to three.
Why CSS units don't help
CSS has mm and in, so it is tempting to write width: 17.3mm and move on. Don't. By definition, a CSS inch is 96 CSS pixels, and that is a reference value, not a measurement of your actual screen. On a real display, 17.3mm renders at whatever size the OS and panel happen to produce. It is only correct by accident.
So the real problem is to find CSS pixels per millimeter (I call it pxPerMM) for this specific screen. Everything else is just drawing a circle at diameterMM * pxPerMM. I ended up supporting three ways to get that number, because every one of them fails for some people.
Method 1: fingerprint the device
The browser does tell you a few things: screen.width, screen.height and devicePixelRatio. Together they are a rough fingerprint. An iPhone 13 reports 390 x 844 CSS pixels at a ratio of 3. I keep a table of devices with those values and their published pixels per inch:
ts
export function matchDevice(cssWidth: number, cssHeight: number, dpr: number) {
const dprRounded = Math.round(dpr * 100) / 100;
for (const d of DEVICE_DB) {
const dprClose = Math.abs(d.dpr - dprRounded) < 0.15;
const straight = d.cssWidth === cssWidth && d.cssHeight === cssHeight;
const rotated = d.cssWidth === cssHeight && d.cssHeight === cssWidth;
if (dprClose && (straight || rotated)) return d;
}
return null;
}
Two details matter. Portrait and landscape both have to match (rotated), and the ratio needs a tolerance, because browsers report values like 2.625 or 2.75 that don't equal the number on the spec sheet exactly.
The bug
The matched device gives me a published PPI, for example 460 for most recent iPhones. My first version did this:
ts
pxPerMM = match.ppi / 25.4; // wrong
That gives 18.1 px per mm. It looks reasonable and it is badly wrong. Published PPI describes physical pixels. A CSS pixel on that iPhone is 3 physical pixels wide. The correct calculation divides by the device pixel ratio first:
ts
pxPerMM = match.ppi / dpr / 25.4; // 460 / 3 / 25.4 = about 6.04
At 18.1 px/mm, a 17.3 mm ring was drawn about 313 CSS pixels wide. At 6.04 px/mm it is about 104. Every circle on a high-density screen was exactly dpr times too large, so everyone would have been told to buy a ring that was far too small. It is the kind of bug that survives review, because every number looks plausible. I left a comment in the code explaining why the division exists, since it looks unnecessary until you know.
The fingerprint approach has a weakness: it is a table I maintain, and different panels can share the same CSS size and ratio. That is why it is not the only method.
Method 2: screen diagonal
Most people know their screen size in inches ("a 24 inch monitor", "a 6.1 inch phone"). That is enough to calculate density without any device table. With the diagonal and the CSS resolution, the physical width follows from the aspect ratio:
ts
const w = window.screen.width;
const h = window.screen.height;
const diagonalPx = Math.sqrt(w * w + h * h);
const physicalWidthIn = diagonalIn * (w / diagonalPx);
const cssPxPerInch = w / physicalWidthIn;
const pxPerMM = cssPxPerInch / 25.4;
For a 1920 x 1080 monitor at 24 inches that works out to about 92 CSS pixels per inch. The method assumes square pixels and that the page isn't zoomed, so the UI tells people to reset browser zoom to 100 percent first. I also added a device search that fills the diagonal in automatically, because many people don't know it offhand.
Method 3: hold a card or a coin to the screen
The last method needs no database and no assumptions about the display. The user places a real object on the screen, a bank card (ISO ID-1, 85.6 x 53.98 mm) or a coin, and drags a slider until the on-screen shape matches its edges. Then:
ts
pxPerMM = sliderPx / objectWidthMM;
This is the most trustworthy method, and the clunkiest, which is why it is the fallback.
It also had its own bug. My slider originally ran from 80 to 500 pixels. A bank card fits that range on most screens, but a coin (around 23 mm) on a low-density screen needs only about 35 to 90 pixels, so the right answer was literally off the end of the slider. The fix is to scale the slider to the object, assuming screens fall somewhere between roughly 1.5 and 8 pixels per mm:
ts
const min = Math.max(20, Math.round(objectWidthMM * 1.5));
const max = Math.round(objectWidthMM * 8);
const start = Math.round(objectWidthMM * 3.8); // roughly 96 DPI
After calibration
Once pxPerMM is known, the rest is simple. The ring-size slider's pixel range is rebuilt from it so it always covers about 8 to 28 mm. The measured diameter is px / pxPerMM, and a lookup table maps that diameter to US, UK, EU, India, Japan and China sizes. Wide bands get a size bump, since a wide band fits tighter than a thin one at the same diameter.
Lessons
Never trust a number you can't connect to a physical object. Published PPI, CSS inches and the screen diagonal all looked plausible while being wrong or fragile. The only ground truth is something with a known real-world size.
Test against a physical object. A unit test can happily confirm a wrong formula. Holding a real ring or card up to the screen is the check that catches it.
Offer more than one route to the same value. Each method fails for somebody: unknown devices, unknown diagonals, no card to hand. Three paths to pxPerMM cover far more people than one clever path.
Be honest about accuracy. An on-screen tool is good, not perfect. The guides on the site recommend measuring on two different days and comparing the result with a ring you already own that fits.
The rest of the stack
The site is Astro, static, on Cloudflare Pages, with six languages. Mobile Lighthouse performance went from 63 to 99, helped by not letting third-party scripts compete with first paint: ads and analytics load on the first user interaction (or after ten seconds as a fallback), and only the two most-used font files are preloaded.
If you want to try the calibration yourself, the tool is free at checkmyringsize.com. I'd especially like to hear if auto-detect picks the wrong device on yours, since that is the part that depends on my device table.

