You reduce a viewport to phone width and the page slides sideways. Adding overflow-x: hidden to body removes the symptom, but it can also clip a menu, a focus ring or content the user needs. Find the box that exceeds the viewport first.
Measure the mismatch
In DevTools, compare document.documentElement.scrollWidth with clientWidth. If the first is larger, inspect elements whose right edge lies beyond the viewport. This temporary console probe identifies candidates; it does not edit the page:
const edge = document.documentElement.clientWidth;
[...document.querySelectorAll('body *')]
.filter((element) => element.getBoundingClientRect().right > edge + 1)
.slice(0, 20)
.map((element) => ({ element, right: element.getBoundingClientRect().right }));
The first reported descendant is not necessarily the cause. Inspect its ancestors and computed layout. A wide code block may need its own horizontal scrolling; a media element may need max-width: 100%; an unbreakable token may need wrapping. An element set to 100vw can exceed the content area when a vertical scrollbar consumes space. MDN explains the overflow properties.
Check minimum sizes in flex and grid
Flex and grid items often refuse to shrink because their automatic minimum size follows their content. Give the intended shrinking item min-width: 0, then put any needed scrolling on the specific child, such as a code block or table. MDN's min-width reference documents the automatic minimum and its exceptions.
.article-layout { display: grid; grid-template-columns: minmax(0, 1fr) 16rem; }
.article-main { min-width: 0; }
.article-main pre { max-width: 100%; overflow-x: auto; }
@media (max-width: 42rem) {
.article-layout { grid-template-columns: minmax(0, 1fr); }
}
Recheck at 320px, 360px and a wider mobile width, then zoom text. The fix is complete when the page stays within the viewport while the intentionally scrollable content remains reachable.