Overflow controls how content outside a box is clipped or scrolled. It does not repair a bad information structure or create alternate text for hidden content.
CSS overflow: contain long data without losing controls
How the rule works
An audit report includes a long machine identifier and a wide data table. Both may need local horizontal scrolling on a phone. Wrap only the region that genuinely exceeds the available inline size, keep focusable controls visible, and make the scroll region discoverable. Setting overflow: hidden on the body to suppress a horizontal scrollbar can hide the actual error and trap a keyboard user's focus. When a string has safe break points, overflow-wrap may be better than a scroller. Avoid clipping a box shadow or focus ring just to make a screenshot look clean.
.audit-code { max-inline-size: 100%; overflow-x: auto; }
.audit-code code { white-space: pre; }
.case-identifier { overflow-wrap: anywhere; }
.audit-table-wrap { max-inline-size: 100%; overflow-x: auto; }Cost and verification
A local scroll container adds no network bytes, but nested scrolling costs attention and may be awkward on touch devices. Test keyboard reachability, focus visibility, and a 320-pixel viewport. The table still needs semantic headers in HTML; horizontal scrolling does not supply relationships. If long content is generated, check that the wrapper can shrink inside grid or flex layouts, often with min-inline-size: 0.
Common Mistakes
- Do not hide page overflow to conceal an oversized child.
- Do not break a code sample in a way that changes the value a reader copies.
- Do not treat scrolling as a replacement for table headers.
Connected lessons
- CSS Layout
- CSS grid tracks: reserve a sidebar without letting content widen the page
- CSS box model and layout: size content without accidental overflow
- HTML complex tables: connect each value to all applicable headers
Extend this decision
- CSS scroll snap: align cards without trapping the reader
- CSS overscroll behavior: stop unwanted scroll chaining
- CSS content-visibility: skip offscreen rendering carefully
Further rendering decisions
Further form and type decisions
Further interaction details
- CSS overflow-anchor: exclude a volatile child, not the whole feed
- CSS scrollbar-color: keep the scroll affordance visible
