Skip to content
AITroveRead. Build. Understand.
Make this comfortable

CSS overflow: contain long data without losing controls

Last updated: 1 Oct 20265 min read
tutorial
BeginnerBy AITrove Editorial

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.

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.

css
.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

Extend this decision

Further rendering decisions

Further form and type decisions

Further interaction details

Further rendering decisions

css
layout
web
Storage details