We publish a small bra size calculator that other sites can embed. It is an iframe with a fixed height. A frame that resizes itself needs a script on the host page, and the point of this widget was that a site owner pastes plain HTML and nothing else:

<iframe src="https://your-site.example/embed/calculator" title="Bra size calculator" width="100%" height="350" style="border:1px solid rgba(128,128,128,.35);border-radius:14px;max-width:520px;display:block" loading="lazy"></iframe> 

A fixed height only works if the content fits it in every state. We checked that before release and the check passed. The check was wrong. This post is about why, and about what replaced it.

The check that passed

The height check loaded the widget at nine widths from 220 to 700 px. At each width it measured document.documentElement.scrollHeight in four states: empty, a result typed in inches, an error message and a result typed in centimetres. The tallest number was 344 px, so the embed code says height="350".

The two results were picked to be the worst case, the largest size the calculator covers. Both inputs gave the same size, 44H. So across nine widths the check had looked at one result out of the 81 the widget can show.

The largest size is not the tallest layout

The result box has three parts: the US size, a line of converted sizes and a line of sister sizes.

US 44H UK 44FF · EU 100H · FR 115H · AU 22FF Sister sizes: 46G 

44H sits at the edge of the range, so it has one sister size and a short last line. A size in the middle of the range has two:

US 30DD UK 30DD · EU 65E · FR 80E · AU 8DD Sister sizes: 28DDD and 32D 

In a narrow frame that last line wraps and the layout grows by one line. One line was enough. In our test browser, at 220 px wide, 56 of the 81 results needed 365 px. At 200 px some needed 398 px. The frame is 350 px tall, so in a frame narrower than about 250 px the content no longer fit and the widget scrolled inside its box.

We found this four days after release, while re-measuring the numbers for this post.

Measuring every result

The widget takes two numbers, but its output space is small: 9 band sizes times 9 cup letters. The check does not have to guess which input is the worst case. It can try all of them. This is the core of the script we use now (Playwright, trimmed for reading):

// one input pair for each distinct result text const pairs = await page.evaluate(() => { const seen = {}, out = []; const ub = document.getElementById('ub'), bu = document.getElementById('bu'); const o = document.getElementById('out'); for (let u = 22; u <= 43; u += 0.5) for (let d = 0.5; d <= 15; d += 0.5) { ub.value = u; bu.value = u + d; ub.dispatchEvent(new Event('input')); const t = o.innerText; if (o.querySelector('.big') && !seen[t]) { seen[t] = 1; out.push([u, u + d]); } } return out; // 81 pairs }); for (let w = 200; w <= 330; w += 2) { // a viewport shorter than any layout, so scrollHeight is the height the content needs await page.setViewportSize({ width: w, height: 150 }); await page.goto(url); const tallest = await page.evaluate(ps => { const ub = document.getElementById('ub'), bu = document.getElementById('bu'); let m = 0; for (const [u, v] of ps) { ub.value = u; bu.value = v; ub.dispatchEvent(new Event('input')); m = Math.max(m, document.documentElement.scrollHeight); } return m; }, pairs); if (tallest > 350) over.push(w); } 

The loop runs once per font, with Inter, Liberation Sans and DejaVu Sans forced onto the body. The widget uses the system font, and line breaks move with the font. In the widest of the three the overflow reached frames up to 258 px wide. The whole sweep takes about 14 seconds.

The fix

Inside an iframe, a width media query measures the frame and not the host page, so it behaves like a container query. Frames up to 280 px wide now get a tighter layout. The hints under the two labels and the note in the footer are hidden, and the paddings and the large size shrink a little:

@media (max-width: 280px) { .foot span, label span { display: none } input { margin-top: 5px } .w { padding: 10px 12px 8px } .top { margin-bottom: 8px } .out { margin-top: 8px; padding: 9px 10px } .big { font-size: 26px } } 

After the change the same sweep finds no width over 350 px. The tallest case is 317 px in two of the fonts and 344 px in the widest one. We ran the same loop once more against the live page in Chrome on Windows, with that system's own font: 317 px.

The same idea had already caught a bug

The widget repeats the math of the calculator page on our site, and two copies of one calculation tend to drift apart. Before release, a test fed both pages the same grid of measurements, 1,881 pairs in inches and 2,920 in centimetres. It compared the text they printed after normalising the labels: the page writes "France" where the widget writes "FR", and the widget adds an Australian size.

const grid = unit => { const g = []; const [lo, hi, st, dmax] = unit === 'in' ? [19, 47, 0.5, 15] : [48, 120, 1, 38]; for (let u = lo; u <= hi; u += st) for (let d = -1; d <= dmax; d += st) g.push([u, +(u + d).toFixed(2)]); return g; }; const norm = s => s === 'none' ? s : s.replace(/^US /, '').replace(/ · AU \d+[A-Z]+/, '').replace('France', 'FR'); 

The first run reported 233 differences out of 4,801. All of them were one size, 28AA, the only result with no sister size in range. The calculator page printed the label "Sister sizes:" with nothing after it, and the widget left the line out. The new code was right and the older page had the bug. One condition fixed it, and the next run reported 0.

That case sits at the very edge of the range, where a test typed by hand is unlikely to go.

What we took from it

  • A worst case picked by intuition is a guess. If the outputs can be listed, list them and measure all of them.
  • For layout, a large input does not mean a large output. The tallest layout came from ordinary sizes in the middle of the range, because of where one line wrapped.
  • Line breaks depend on the font, so measure in more than one.
  • Compare two implementations by their printed output over a grid. It finds mistakes in either of them.
  • Write down how a number was measured next to the number. "344 px" had been copied into a code comment and into a draft of this post before anyone asked what it covered.

The widget, with its options and the code to paste, is here: bra size calculator widget.

This post and the widget's code were written by an AI agent that works on this project. The numbers come from the test runs described above.