Engineering / Field note
A page can fit while its controls collide
Five fictional browser examples show why document width, control overlap and enlarged text need separate checks. A passing width assertion covers only one part of an interface.
A page can stay within its viewport while two buttons occupy the same space. A width assertion may pass even though one action covers part of another. Checking the page edges remains useful, but the relationships between controls deserve their own observation. Everything can stay inside the fence while the buttons park on each other.
This field note reviews established browser measurements and accessibility guidance on December 1, 2026. The examples are original fictional fixtures, with no private website, incident or browser defect represented. W3C’s guidance concerns preserving information and functionality as layouts and text sizes change; a single width measurement covers only part of that question. [4] [5]
Measure the document’s width
MDN defines scrollWidth as the width of an element’s content, including overflowing content. It describes clientWidth as the inner width; on the root element in a standards-mode document, that gives the viewport width excluding any scrollbar. Comparing those measurements can flag a document that extends horizontally beyond its viewport. [1] [2]
const root = document.documentElement;
const widths = {
visible: root.clientWidth,
scrollable: root.scrollWidth,
};
if (widths.scrollable > widths.visible) {
throw new Error("Document is wider than its viewport");
}Our controlled page has a .demo-toolbar container and two native buttons, marked data-demo="first" and data-demo="second". The initial buttons are absolutely positioned with overlapping horizontal ranges. Both remain inside the page. The first assertion therefore passes in this deliberately faulty arrangement. Its result is accurate: the document fits.
Compare the controls explicitly
MDN documents getBoundingClientRect as returning an element’s size and position relative to the viewport, including its padding and borders. That gives both controls a shared coordinate system. The next helper checks whether their rectangles share a positive area. Its explicit cases include a collision, containment, separation and edges that merely touch. [3]
function overlaps(a, b) {
const width = Math.min(a.right, b.right)
- Math.max(a.left, b.left);
const height = Math.min(a.bottom, b.bottom)
- Math.max(a.top, b.top);
return width > 0 && height > 0;
}
const base = {left: 0, top: 0, right: 100, bottom: 40};
const cases = [
[{left: 80, top: 0, right: 180, bottom: 40}, true],
[{left: 100, top: 0, right: 200, bottom: 40}, false],
[{left: 0, top: 40, right: 100, bottom: 80}, false],
[{left: 10, top: 10, right: 20, bottom: 20}, true],
[{left: -50, top: 5, right: -1, bottom: 25}, false],
[{left: 80, top: 50, right: 180, bottom: 90}, false],
];
for (const [other, expected] of cases) {
if (overlaps(base, other) !== expected) {
throw new Error("Unexpected rectangle comparison");
}
}This comparison is a geometric warning for a pair that should stay separate. Intentional overlays, decorative badges and nested boxes need different expectations. Applying the helper indiscriminately to every element pair would produce a generous collection of unhelpful alarms. Choose the relationship the component is supposed to preserve.
const a = document.querySelector('[data-demo="first"]')
.getBoundingClientRect();
const b = document.querySelector('[data-demo="second"]')
.getBoundingClientRect();
const overlapWidth = Math.min(a.right, b.right)
- Math.max(a.left, b.left);
const overlapHeight = Math.min(a.bottom, b.bottom)
- Math.max(a.top, b.top);
if (!(overlapWidth > 0 && overlapHeight > 0)) {
throw new Error("Expected the fictional collision");
}In the original fixture, the measured rectangles overlap and the second button occupies a point in their shared area. After the layout change below, that positive overlap disappears. These are observations about the controlled example. A bounding rectangle alone does not establish readable text, contrast, complete visibility or correct interaction.
Keep text resizing and reflow in the picture
W3C’s Resize Text explanation for WCAG 2.2 describes resizing text up to 200 percent without losing content or functionality, with exceptions for captions and images of text. It discusses user-agent mechanisms including page zoom and text resizing. The practical consequence is broader than making the document’s right edge behave: controls and labels must remain usable as their text grows. [5]
W3C’s Reflow explanation describes preserving information and functionality without requiring two-dimensional scrolling at the specified sizes. For vertically scrolling content, the width is equivalent to 320 CSS pixels; content requiring a two-dimensional layout has an exception. The guidance includes more than the absence of a horizontal scrollbar, and this small fixture cannot establish a whole page’s conformance. [4]
Let the fictional controls take their space
The next CSS changes our toolbar into a grid and returns its buttons to normal grid placement. The column minimum can shrink to the container width, labels can wrap, and height can grow. At narrower widths the controls can occupy separate rows. This is one local layout recipe, chosen for these two fictional actions.
.demo-toolbar {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
height: auto;
padding: 1rem;
}
.demo-toolbar button {
position: static;
width: auto;
min-width: 0;
min-height: 2.75rem;
white-space: normal;
overflow-wrap: anywhere;
}The repair preserves both native buttons. The fixture checks that each can receive keyboard focus and activate. That adds a useful interaction observation alongside the geometry measurements. A real component still needs its own labels, focus treatment, content and behavior reviewed in context.
Exercise a small matrix
The final example assumes a Playwright page already contains the repaired fixture. Playwright’s page API provides viewport resizing. The loop varies width and the toolbar’s CSS font size independently, retaining both fit and overlap results. It changes an already loaded controlled page, which makes it a component check rather than a navigation test. [7]
async function inspect(page, width, fontSize) {
await page.setViewportSize({width, height: 900});
await page.locator(".demo-toolbar").evaluate((node, size) => {
node.style.fontSize = size + "px";
}, fontSize);
await page.evaluate(() => document.fonts.ready);
return page.evaluate(() => {
const root = document.documentElement;
const a = document.querySelector('[data-demo="first"]')
.getBoundingClientRect();
const b = document.querySelector('[data-demo="second"]')
.getBoundingClientRect();
return {
documentFits: root.scrollWidth <= root.clientWidth,
controlsOverlap:
Math.min(a.right, b.right) > Math.max(a.left, b.left)
&& Math.min(a.bottom, b.bottom) > Math.max(a.top, b.top),
};
});
}
const results = [];
for (const width of [320, 640, 1024]) {
for (const fontSize of [16, 32]) {
const result = await inspect(page, width, fontSize);
results.push({width, fontSize, ...result});
if (!result.documentFits || result.controlsOverlap) {
throw new Error("Layout check failed: " + JSON.stringify(result));
}
}
}The 16-to-32-pixel font change models enlarged text in this fixture. It is not native browser zoom, a mobile-device result or a complete accessibility audit. Use actual supported browser resizing and interaction checks when assessing a real page, including intermediate widths where controls can meet before the layout changes.
We executed the examples in headless Chromium 151.0.7922.34, with the CSS applied to the real fixture DOM. The checks include an oversized sibling, a deliberately reintroduced collision and keyboard activation. Every fixture request was intercepted; no production account or external fixture service was used.
Our earlier disclosure field note separates control state, geometry and image readiness. This example adds another relationship worth keeping explicit: document fit and separation between controls. Retain each observation, inspect the rendered result, and let a failure identify which promise the interface actually broke. [6]
Sources + further reading
Source dates describe the original material. Publication above is the date this Zyel article went live.
- Element: scrollWidthMDN Web Docs · Checked Dec 1, 2026
- Element: clientWidth and the root viewportMDN Web Docs · Checked Dec 1, 2026
- Element: getBoundingClientRectMDN Web Docs · Checked Dec 1, 2026
- Understanding WCAG 2.2: ReflowW3C Web Accessibility Initiative · Checked Dec 1, 2026
- Understanding WCAG 2.2: Resize TextW3C Web Accessibility Initiative · Checked Dec 1, 2026
- A rectangle does not prove a disclosure is openZyel · Checked Dec 1, 2026
- Playwright Page API: setViewportSizePlaywright · Checked Dec 1, 2026
Reader discussion
What would you ask next?
Questions, useful corrections and thoughtful disagreement are welcome. Comments are reviewed before they appear.
No reader comments yet.