When the content inside an element (large text, high-resolution image, or wide table) exceeds the explicit dimensions (width or height) of its container box, the overflow property dictates how the browser engine handles the spillover.
| Value | Visual Behavior | Scrollbars Displayed? | Impact on Child Elements |
|---|---|---|---|
visible |
Default. Content spills outside boundaries onto surrounding layout. | No | Can overlap adjacent cards and break UI readability. |
hidden |
Content exceeding dimensions is sliced off and invisible. | No scrollbars | Prevents page blowout; no programmatic scroll available. |
scroll |
Content is clipped and scrollbars are always displayed. | Always visible (even if content fits!) | Looks clunky if content does not need scrolling. |
auto |
Intelligent. Scrollbars appear only when content overflows. | Appears conditionally | Recommended for code blocks, chat windows & modal bodies. |
clip |
Modern CSS value. Clips content strictly without creating a scroll container. | Never | High-performance alternative to hidden for corner masks. |
Mobile websites frequently suffer from annoying horizontal bounce or full-page scrolling when a user scrolls inside a modal. Modern CSS solves both issues effortlessly:
/* 1. Prevent accidental horizontal scrollbars on entire page */
body {
overflow-x: hidden;
}
/* 2. Prevent scroll chaining in modal dialogs */
.modal-body {
max-height: 400px;
overflow-y: auto;
overscroll-behavior: contain; /* Prevents scroll from leaking to background body! */
}
Boost your CSS and front-end development proficiency by exploring these closely connected topics:
Understand margins, borders, padding, content and the universal box-sizing fix.
Master 1D alignment, justify-content, align-items, flex-wrap and responsive flow.
Build powerful two-dimensional grid layouts with template areas and fr units.
Eliminate styling conflicts and master selector weights from 0,0,0,1 to !important.