Skip to content

Topics

Jump to a topic.

Search questions

Find a question by title, tag, or summary.

What does overflow do, and how is overflow: clip different from hidden?

Questions in this chapter (8)
  • Draft
  • medium
  • Askedoften
  • Verified October 2026

Answer

Content overflows when it extends past the box's padding edge: a long word, a fixed-height card, a wide table. overflow (shorthand for overflow-x and overflow-y) picks the handling:

  • visible (initial): overflow paints outside the box. Not a scroll container.
  • hidden: clips to the padding box with no scrollbars or user scrolling, but the box is still a scroll container. Script can scroll it (scrollTop, scrollIntoView()), and so can focusing an element inside it.
  • scroll: clips and always shows a scrolling mechanism.
  • auto: like scroll when there's overflow, like hidden otherwise. Usually what you want.
  • clip: clips to the overflow clip edge and forbids scrolling through any mechanism. It is not a scroll container.

Being a scroll container has side effects, and they're the point of the hidden vs clip question:

  • It establishes a new block formatting context (contains floats, stops margin collapsing). clip doesn't.
  • It becomes the scrollport for position: sticky descendants, so a sticky header inside an overflow: hidden wrapper sticks to the wrapper, not the page. With clip it still sticks to the viewport.
  • It can be scrolled by focus and by scrollIntoView(), which makes hidden carousels jump.

So overflow: clip is the "just cut it off visually" value; hidden is "a scroller without a scrollbar".

Two mixing rules. If one axis is scrollable, visible in the other axis computes to auto and clip to hidden: overflow-x: hidden alone gives you overflow-y: auto. overflow-x: clip leaves overflow-y: visible, which is the reliable way to clip one axis only.

And overflow set on <html>, or on <body> when <html> is visible, goes to the viewport instead of the element.

Example

<style>
  .box { width: 100px; height: 100px; }
  .big { width: 300px; height: 300px; }
  .hidden { overflow: hidden; }
  .clip { overflow: clip; }
  .x-hidden { overflow-x: hidden; }
  .x-clip { overflow-x: clip; }
</style>
<div class="box hidden"><div class="big"></div></div>
<div class="box clip"><div class="big"></div></div>
<div class="box x-hidden"></div>
<div class="box x-clip"></div>
<script>
  const [hidden, clip, xHidden, xClip] = document.querySelectorAll(".box");
  hidden.scrollTop = 50;
  clip.scrollTop = 50;
  console.log(hidden.scrollTop, clip.scrollTop);
  console.log(getComputedStyle(xHidden).overflowY, getComputedStyle(xClip).overflowY);
  // → 50 0
  // → auto visible
</script>

The hidden box scrolled from script; the clip box ignored it. Clipping one axis with hidden silently made the other axis auto. Chrome 155 and Firefox 158 agreed.

Pitfalls

  • Adding overflow-x: hidden to stop horizontal scroll and breaking position: sticky inside it. The element became a scroll container; a sticky child scrolled away at -400px while the same child under overflow-x: clip stayed at 0.
  • Expecting overflow: hidden to stop all scrolling. Focusing the third button in a 200px "carousel" scrolled it in both browsers; with clip, scrollLeft stayed 0.
  • Using overflow: hidden to clear floats and clipping focus rings and shadows as a side effect. Use display: flow-root for containment.
  • Expecting overflow to clip an absolutely positioned child whose containing block is outside the box. Clipping applies only to descendants whose containing block is the box or inside it.

Follow-ups

What does overflow-clip-margin do?
It pushes the clip edge out from the box, e.g. overflow: clip; overflow-clip-margin: 20px lets content paint 20px past the padding box, so shadows survive. It has no effect on hidden. Firefox 102 supports it; Chrome's support is partial (both axes must be clip).
Does a scroll container's padding count at the end of its scrollable area?
Yes in both browsers: a 100px box with 20px bottom padding around a 300px child with a 50px bottom margin had scrollHeight 370, in block, flex and inline-axis cases. Overflow 3 lets UAs include those margins.
Does overflow: hidden on <body> clip the body?
Not while <html> is visible: the value propagates to the viewport and the body's used value becomes visible. Overflow 3 also notes that on the root it may not clip everything outside the initial containing block when that's smaller than the viewport, which can happen on mobile.

Exercises

Which track moves when the third button is focused?

<style>
  .track { width: 200px; height: 50px; white-space: nowrap; }
  .track button { width: 200px; height: 50px; }
  #a { overflow: hidden; }
  #b { overflow: clip; }
</style>
<div class="track" id="a"><button>1</button><button>2</button><button id="a3">3</button></div>
<div class="track" id="b"><button>1</button><button>2</button><button id="b3">3</button></div>
<script>a3.focus(); b3.focus();</script>

Comments

Comments are GitHub Discussions: you sign in with GitHub to post or react.