Overflow & scroll containers

오버플로우와 스크롤 컨테이너

Four overflow values that decide what happens when content is bigger than its box — let it spill, clip it, or turn it into a scrollbar.

Also known as: overflow: auto/hidden/scroll/clip
···
html
<div class="wrap" id="wrap">
  <div class="cell"><b>visible</b><div class="box vis"><i></i><i></i><i></i><i></i></div></div>
  <div class="cell"><b>hidden</b><div class="box hid"><i></i><i></i><i></i><i></i></div></div>
  <div class="cell"><b>scroll</b><div class="box scr"><i></i><i></i><i></i><i></i></div></div>
  <div class="cell"><b>auto</b><div class="box aut"><i></i><i></i><i></i><i></i></div></div>
</div>
css
.wrap{display:grid;grid-template-columns:repeat(auto-fit,minmax(96px,1fr));gap:18px 14px;row-gap:44px;
  width:min(94%,480px);transition:width 2.6s cubic-bezier(.4,0,.2,1)}
.cell{display:flex;flex-direction:column;align-items:center;gap:6px}
.cell b{font:700 10px/1 ui-monospace,monospace;color:var(--muted)}
.box{position:relative;width:72px;height:56px;border:2px solid var(--line);border-radius:8px;background:var(--surface)}
.vis{overflow:visible}
.hid{overflow:hidden}
.scr{overflow:scroll}
.aut{overflow:auto}
.box i{display:block;height:13px;margin:4px 8px;border-radius:3px;background:var(--accent)}
.box i:nth-child(even){background:var(--accent-3)}
js
const wrap = document.getElementById('wrap');
setInterval(() => wrap.style.width = wrap.style.width === '48%' ? 'min(94%, 480px)' : '48%', 2600);

overflow: visible (the default) does nothing — content simply spills past the box edge and can overlap neighboring elements. hidden clips the overflow and provides no way to reach it — users have no means to see the cut-off content. scroll always shows a scrollbar whether content overflows or not; auto only creates one when content actually overflows — auto is the right answer for most "scrollable area" needs.

clip (a comparatively recent value) crops like hidden, but also blocks scrolling programmatically — hidden can still be scrolled via JS methods like scrollTo(), while clip can't be scrolled at all. It also accepts overflow-clip-margin, letting content extend a few pixels past the edge before being clipped — handy for a shadow that shouldn't get cut off.

overflow-x and overflow-y set each axis independently. A common trap: overflow: hidden on a parent that contains a position: sticky child — sticky stops working the moment its nearest scrollable ancestor's overflow isn't visible.

When to use

auto is the default choice for a fixed-size viewport whose contents scroll internally — a long list in a modal, a chat window, a code block. If a design element intentionally spills slightly past its box, just leave overflow as visible.