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: likescrollwhen there's overflow, likehiddenotherwise. 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).
clipdoesn't. - It becomes the scrollport for
position: stickydescendants, so a sticky header inside anoverflow: hiddenwrapper sticks to the wrapper, not the page. Withclipit still sticks to the viewport. - It can be scrolled by focus and by
scrollIntoView(), which makeshiddencarousels 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.