In CSS, what is the difference between overflow: hidden and overflow: clip?
answer
- identical picture, different machinery
- one of them still has a scroll offset
- focus can move content you thought was frozen
- only one has a clip margin
- only one may pair with visible
basics
~20 sBoth clip content that does not fit, but overflow: hidden makes the element a scroll container that can still be scrolled programmatically, while overflow: clip creates no scroll container at all and can be paired per-axis with visible.
solid answer
~50 sThey look identical on screen and behave very differently underneath. `overflow: hidden` clips *and* turns the box into a scroll container: no scrollbars are offered to the user, but the scrollable area exists, so the browser can scroll it — move keyboard focus into the clipped region and the content jumps. `overflow: clip` clips without creating a scroll container, so nothing can scroll it by any means; it is the honest way to say "just cut this off". `clip` also has two abilities `hidden` lacks: `overflow-clip-margin` can push the clip edge outward by a length, useful when a focus ring or shadow would otherwise be shaved off, and it can be mixed per axis with `visible` — `overflow-x: clip` leaves `overflow-y: visible` intact, whereas `overflow-x: hidden` forces the other axis to compute to `auto`. `clip` has been supported across all major engines since Safari 16 in 2022.
code
css · 9 lines.card {
overflow: clip;
overflow-clip-margin: 3px;
}
.toolbar {
overflow-x: clip;
overflow-y: visible;
}go deeper
Know that both values cut off content that does not fit, and that clip is the newer value meaning "clip and never scroll" while hidden still leaves a scrollable box behind.
Explain the scroll-container difference and its visible consequence: focus moving into clipped content scrolls a hidden box, and clip is the value that pairs legally with visible on the other axis.
Bring judgment about which one an existing codebase should use where, the focus and scroll-restoration bugs hidden causes, and using overflow-clip-margin so clipping does not shave off focus indicators.
Own the convention across a large stylesheet: default to clip for visual containment, treat every hidden as a deliberate scroll container, and decide how that migration is enforced in review or tooling.
## Same picture, different machinery Render a box with `overflow: hidden` and the same box with `overflow: clip` and you cannot tell them apart in a screenshot. The difference is structural: `hidden` produces a **scroll container**, `clip` does not. A scroll container has a scrollport (the visible window) and a scrollable overflow area (everything laid out inside it). The fact that no scrollbars are drawn for `hidden` is a rendering decision, not a statement about scrollability. The container is fully scrollable — just not through a user affordance. ## Why that matters in practice The consequences of accidentally creating a scroll container are the reason this question gets asked: - **The browser can scroll it for you.** If something inside the clipped region receives keyboard focus, or the page navigates to a fragment that lands there, the browser scrolls the clipped content into view. Users see a panel whose top row has silently vanished and no way to scroll back — the scrollbars they would need do not exist. - **Scroll position becomes state.** A scroll container remembers an offset. That offset can be restored on navigation or changed by a nested interaction, producing "why is this box scrolled?" bugs that are invisible in the CSS. - **The box becomes the scroll parent for descendants.** Anything that behaves relative to "the nearest scrolling ancestor" now resolves to this box instead of the page. `overflow: clip` has none of these effects. There is no scrollport, no offset, and no way for user or browser to move the content. When your intent is genuinely "cut off whatever pokes out" — a rounded avatar clipping an image, a decorative shape kept inside a card — `clip` says exactly that. ```css .avatar { inline-size: 3rem; aspect-ratio: 1; border-radius: 50%; overflow: clip; /* not hidden — nothing here should ever scroll */ } ``` ## The clip margin `clip` clips at the *overflow clip edge*, which by default coincides with the padding box. `overflow-clip-margin` moves that edge outward by a length or from a named box: ```css .chip { overflow: clip; overflow-clip-margin: 4px; /* let a focus ring bleed out */ } ``` This solves a real annoyance: clipping a box also shaves off focus rings, outlines and small decorative overhangs that ought to survive. `hidden` has no equivalent knob — the clip edge is the padding edge, full stop. ## Per-axis pairing The pairing rules are the other practical difference. CSS forbids the combination "scrollable in one axis, spilling in the other" for a scroll container: if one of `overflow-x`/`overflow-y` is `visible` and the other is a clipping-and-scrolling value, the `visible` one computes to `auto`. So `overflow-x: hidden; overflow-y: visible` quietly becomes `overflow-y: auto`, and vertical overflow gets clipped and scrolled instead of spilling. `clip` sidesteps this because it is not a scrolling value: `overflow-x: clip` with `overflow-y: visible` is legal and stays as specified. That makes it the correct tool for "stop the horizontal spill but let this dropdown escape downward": ```css .row { overflow-x: clip; overflow-y: visible; /* stays visible — a menu can still escape */ } ``` (Symmetrically, `clip` paired with a scrolling value in the other axis computes to `hidden`.) ## Choosing between them Use `clip` whenever the intent is purely visual containment. Reserve `hidden` for the case where you want a scroll container without user-visible scrollbars — for example a viewport you scroll from script or via scrolling APIs, or a masked strip you drive yourself. If you catch yourself writing `overflow: hidden` next to a comment saying "just to clip the corners", that is a `clip`. Browser support is not a reason to avoid `clip` any more: Firefox shipped it in 2020, Chrome in 2021, Safari in version 16 in 2022. It is worth knowing the older habit exists though — a great deal of existing CSS uses `hidden` for clipping simply because `clip` did not exist when it was written.
- Give a concrete bug caused by using overflow: hidden where overflow: clip was meant.A fixed-height card clips a list with `overflow: hidden`. A link three rows below the fold gets keyboard focus — via tabbing or a fragment target — and the browser scrolls the card's scroll container to reveal it. The card's header scrolls out of sight with no scrollbar to bring it back, so the layout appears broken and cannot be recovered by the user. `overflow: clip` creates no scroll container, so nothing moves.
- When is overflow: hidden still the right choice over clip?When you actually want a scroll container without user-facing scrollbars: a strip you scroll from script, a carousel viewport driven by your own controls, or a container whose scroll position you manage deliberately. `hidden` keeps the scrollport and the scroll offset; `clip` throws both away. If you want the affordance hidden but the user still able to scroll, `scrollbar-width: none` on an `auto` container is closer to what you mean.
- What does overflow-clip-margin do, and when do you need it?It moves the overflow clip edge outward from its default position at the padding box by a given length, so content within that margin is not clipped. It is the fix for clipped focus rings, outlines and small decorative overhangs on an element that must otherwise clip. It only applies where the box actually clips with `clip`; `hidden` has no equivalent.
saying these in an interview costs you the question
- Says clip and hidden are simply aliases
- Thinks hidden makes content permanently unreachable
- Assumes overflow-x: hidden leaves the y axis visible
- Uses hidden for rounded-corner clipping without thinking
- Believes clip can still be scrolled from script