CSS overflow: clip vs. hidden: Performance Differences and Layout Isolation
AI generated
CSS · Performance · overflow · Stacking Context
CSS overflow: clip vs. hidden
Stacking context, paint containment and layout isolation

overflow: clip is the more modern, often more performant alternative to overflow: hidden. The decisive difference is not in the visible result but in the invisible side effects: clip creates no stacking context and no new block formatting context, so it avoids unwanted z-index problems and enables more precise paint isolation for the browser renderer.

11 min read overflow: clip · hidden · stacking context · BFC · paint containment Chrome 90+ · Firefox 81+ · Safari 16+ · 2026

1. The problem with overflow: hidden

overflow: hidden is one of the most widely used CSS properties, and at the same time one of the most misunderstood. It is often used to cut off overflowing content: images that spill out of their container, card content that should not stick out, or decorative elements that need to be clipped at the edges. What rarely gets considered is that overflow: hidden does more than just cut off content. It creates a new block formatting context (BFC) and, in certain combinations, a new stacking context, with far-reaching consequences for layout and z-index behavior in the DOM.

A new block formatting context means that floats from the parent element can no longer escape the container, that margin collapsing with neighboring elements no longer happens, and that certain layout calculations take place in isolation. That can be intentional, but in many cases overflow: hidden is only applied for its clipping effect, and the BFC side effects are unwanted. The same applies to the stacking context: setting overflow: hidden on an element that has a CSS transform or another stacking context trigger can create unexpected z-index conflicts that are hard to debug.

2. overflow: clip, what it actually does

overflow: clip was specified in CSS Overflow Level 3 and has been available without prefixes since Chrome 90, Firefox 81 and Safari 16. It cuts off content, exactly like overflow: hidden, but with one fundamental difference: it creates neither a new block formatting context nor, in combination with other properties, a new stacking context. The clipping is purely visual and does not affect any other layout mechanism of the element. That is a much cleaner separation of responsibilities: clip the content visually, nothing more.

The second significant difference: overflow: clip fully disables scrollable overflow. While overflow: hidden still allows JavaScript-driven scrolling in certain browsers or under certain circumstances (for example via element.scrollTop), overflow: clip prevents any scrolling, including programmatic scrolling. That makes it the right choice for elements that should never be scrolled, while overflow: hidden remains suitable for elements where programmatic scrolling still needs to be possible.


/* overflow: clip: visual clipping without creating a BFC */
.card-image-wrapper {
  /* Clips the image to border-radius without BFC side effects */
  overflow: clip;
  border-radius: 0.75rem;
}

/* overflow: hidden: clips and creates a BFC */
.clearfix-container {
  /* BFC is the desired effect here, it contains floats */
  overflow: hidden;
}

/* The difference: clip does NOT contain floats */
.float-leak-example {
  overflow: clip;
  /* Floated children WILL escape this container */
  /* (rarely desired, but predictable behavior) */
}

/* overflow: clip with explicit overflow-clip-margin */
.decorative-bleed {
  overflow: clip;
  overflow-clip-margin: 20px;  /* allow 20px bleed before clipping */
}

/* Independent axis clipping */
.horizontal-scroll-clip {
  overflow-x: auto;
  overflow-y: clip;  /* vertical: clip; horizontal: scroll */
}

3. Stacking context: the decisive difference

A stacking context is an isolated z-index space in the DOM. Elements inside a stacking context are rendered as a group and can only compete with each other within that context, not with elements outside it. overflow: hidden alone does not create a stacking context, but in combination with certain other properties such as position: fixed, transform, opacity or will-change, it can be part of a stacking context trigger set. That is often the reason behind the classic bug report: "my modal is behind a container even though it has z-index: 9999."

overflow: clip behaves identically to overflow: visible when it comes to stacking context formation: it does not trigger a stacking context. That is a decisive advantage in complex layouts where z-index hierarchies need to be controlled precisely. In a component-based frontend architecture, where cards, modals and tooltips often need to interact across several nested layers, using overflow: clip instead of overflow: hidden significantly reduces the likelihood of unexpected z-index conflicts.


/* overflow: hidden can cause z-index issues with transforms */
.card-with-animation {
  overflow: hidden;
  border-radius: 1rem;
  /* If transform is added, this creates a stacking context */
  /* Child elements with position: fixed will be clipped */
}

/* overflow: clip is safer, it does NOT create a stacking context */
.card-clip-safe {
  overflow: clip;
  border-radius: 1rem;
  /* transform can be added freely without z-index side effects */
}

/* Stacking context trigger example */
.modal-trigger {
  /* overflow: hidden here would trap z-index for modal children */
  overflow: hidden;   /* AVOID for non-scroll containers with modals */
  position: relative; /* already creates a stacking context */
}

/* Better: use clip for pure visual trimming */
.modal-trigger-safe {
  overflow: clip;      /* no BFC, no extra stacking context trigger */
  position: relative;
}

/* contain: paint: explicit paint isolation */
.isolated-component {
  contain: paint;
  /* Implies overflow: clip behavior plus additional paint optimizations */
}

4. Block formatting context and its side effects

The block formatting context (BFC) is a layout isolation mechanism in the CSS rendering model. An element that creates a BFC isolates its content from certain layout interactions with the outside world. Among the practical effects: floats inside a BFC container no longer escape the container (the clearfix effect), margin collapsing between a BFC container and its children does not take place, and the BFC container takes up the full width of its children. These properties are explicitly desired in certain situations: the classic clearfix hack explicitly relies on the BFC created by overflow: hidden.

In modern CSS layouts built with flexbox and grid, floats are rarely used anymore, and the need for clearfix has largely disappeared. What remains is the unwanted side effect of the BFC when overflow: hidden is applied only for clipping: the margin collapsing behavior changes, which can lead to unexpected spacing differences between elements. overflow: clip avoids this problem entirely because it creates no BFC. Anyone using overflow: hidden purely for its clipping effect should replace it with overflow: clip and make the code clearer and easier to maintain.

5. CSS contain and paint containment

CSS containment (contain) is a performance property that tells the browser that an element and its descendants are isolated from a certain type of layout change. The value relevant here in relation to overflow: clip is contain: paint. This keyword tells the browser that all paint operations of the element and its descendants are confined to the element's bounding box. No child content is painted outside that box, which is functionally similar to overflow: clip but with additional rendering optimizations.

The browser can promote elements with contain: paint to their own compositor layer more aggressively, because it is guaranteed that changes inside these elements have no visual effect outside the bounding box. That enables partial repainting instead of full page repaints when the content of the container changes. overflow: clip gives the browser a similar signal, but without the full isolation guarantee of contain: paint. The sensible combination for maximum performance isolation is overflow: clip together with contain: layout paint, which gives the browser the maximum amount of information for render optimizations without creating unnecessary BFC or stacking context side effects.

6. overflow-clip-margin: extending the clip area

One feature exclusive to overflow: clip is the overflow-clip-margin property. It extends the clipping boundary by a given amount, allowing content to stick out of the container by that amount before it gets clipped. That is useful for design elements such as box shadows, outline rings (focus rings) or decorative elements that are meant to extend slightly beyond the container on purpose, without other content becoming visible outside it.

A concrete use case: a card with a pronounced box-shadow. The shadow should be visible and stick out slightly beyond the container, but no other content should be visible outside the container. With overflow: hidden, the shadow would get cut off, which is often undesirable and forces developers to set overflow: visible and reach for other clipping methods. With overflow: clip and overflow-clip-margin: 8px, the shadow can remain visible while the main content is still bound to the container. That is an elegant, semantically clear solution that overflow: hidden simply cannot offer.


/* overflow-clip-margin: allow controlled bleed before clipping */
.card-with-shadow {
  overflow: clip;
  overflow-clip-margin: 8px;  /* shadow bleeds 8px before being clipped */
  box-shadow: 0 4px 16px rgba(74, 29, 150, 0.25);
  border-radius: 1rem;
}

/* Focus rings: visible outside clip boundary */
.interactive-card {
  overflow: clip;
  overflow-clip-margin: content-box 4px;
  /* focus-visible ring extends 4px outside content box */
}

.interactive-card:focus-within {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;  /* stays visible with overflow-clip-margin */
}

/* contain: paint as strong paint isolation */
.composited-panel {
  contain: layout paint;
  overflow: clip;
  /* Browser can promote to own compositor layer for cheap repaints */
}

/* Performance comparison: hidden vs. clip for static content */
.image-card-hidden {
  overflow: hidden;   /* creates BFC, may force relayout on sibling changes */
  border-radius: 0.5rem;
}

.image-card-clip {
  overflow: clip;     /* no BFC, layout isolated only at paint level */
  border-radius: 0.5rem;
}

7. Independent clipping on the X and Y axis

overflow: clip can, like all overflow values, be applied independently on the X and Y axis via overflow-x: clip and overflow-y: clip. That enables layouts where one axis can be scrolled while the other axis is hard clipped. A horizontal scrolling carousel where vertical overflow should be fully clipped is a classic use case: overflow-x: auto; overflow-y: clip. That prevents carousel content from sticking out above or below the container while horizontal scrolling keeps working.

There is a subtlety when combining both axes: browsers have a complex rule for the case where one axis is set to visible while the other axis has a different value. In that case, visible is implicitly rewritten to auto, a spec behavior that often causes confusion. With overflow: clip, this problem is solved: overflow-x: auto; overflow-y: clip works correctly without implicit rewrites, because clip is the only overflow value exempt from this rewriting rule.

8. Practical cases: when clip, when hidden, when scroll?

The decision rule for using overflow: clip versus other overflow values can be structured clearly. overflow: clip is the right choice when the container should never be scrolled (neither by the user nor via JavaScript), when the clipping effect is purely visual and no BFC properties are needed, when a shadow or focus ring should be allowed to bleed slightly using overflow-clip-margin, and when unexpected stacking context effects caused by other properties need to be avoided. These are the most common use cases in modern CSS layouts.

overflow: hidden still makes sense when the BFC is specifically desired, for example to contain floated children (although flexbox and grid replace this need in new layouts), or when programmatic scrolling via JavaScript still needs to remain possible. overflow: scroll and overflow: auto are the right values for genuine scroll containers. With this distinction in mind, overflow: clip will in practice often be the more correct value than the reflexively applied overflow: hidden, more precise in its effect and without unwanted side effects.

Property overflow: hidden overflow: clip overflow: scroll
Visual clipping Yes Yes Yes (with scrollbar)
Block formatting context Yes (side effect) No Yes
Programmatic scrolling Possible No (disabled) Yes
overflow-clip-margin Not available Available Not available
Stacking context risk Higher (with z-index) Low Higher

9. overflow: clip vs. hidden in direct comparison

In day to day frontend development, developers often encounter overflow: clip for the first time while debugging a bug caused by overflow: hidden: a tooltip or modal gets cut off even though it is actually supposed to extend beyond its container. The root of the problem is almost always that overflow: hidden somewhere in the DOM tree becomes an unintended clipping context. The fix using overflow: clip is, in many of these cases, a direct replacement that keeps the visual clipping intact while preventing the unwanted clipping of positioned child elements outside the main content area.

Another optimization pattern: in component-based CSS architectures built with Tailwind CSS or similar utility frameworks, overflow-hidden is often applied reflexively to image containers just to achieve border-radius clipping. With overflow: clip (in Tailwind, a custom utility class or overflow-clip), the visual result is identical, but without the BFC side effects. That is especially relevant when these image containers are embedded in flexbox or grid layouts, where unexpected BFC effects can affect spacing behavior.


/* Real-world pattern: card with rounded image, clip is better */
.product-card {
  border-radius: 1rem;
  overflow: clip;             /* visually clips, no BFC side effects */
  contain: layout paint;      /* hints browser for paint optimization */
  box-shadow: 0 2px 12px rgba(74, 29, 150, 0.15);
}

.product-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

/* Horizontal scroller: independent axis */
.scroll-carousel {
  overflow-x: auto;
  overflow-y: clip;           /* hard clip: no vertical overflow */
  scroll-snap-type: x mandatory;
  display: flex;
  gap: 1rem;
  padding: 0.5rem;
}

.scroll-carousel .item {
  flex: 0 0 280px;
  scroll-snap-align: start;
  overflow: clip;             /* each item clips internally */
  border-radius: 0.75rem;
}

/* Focus ring preserved with overflow-clip-margin */
.focus-safe-button {
  overflow: clip;
  overflow-clip-margin: 4px;  /* focus ring bleeds 4px, stays visible */
  border-radius: 0.5rem;
}

.focus-safe-button:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
}

Mironsoft

CSS performance, rendering optimization and frontend architecture

CSS performance audit: find rendering bottlenecks in your layouts?

We analyze existing CSS codebases for unwanted stacking contexts, superfluous BFCs and missing paint isolation, and replace CSS antipatterns with more performant alternatives such as overflow: clip and CSS containment.

CSS audit

Stacking context analysis and identification of unwanted BFCs and overflow misuse

Refactoring

Replacing overflow: hidden with clip and CSS containment for better paint isolation

Performance

DevTools analysis with layers and paint flashing to measure the rendering improvement

10. Summary

overflow: clip is the more modern and, in many cases, more precise alternative to overflow: hidden. The decisive difference lies in the side effects: overflow: hidden creates a block formatting context that affects margin collapsing and float containment. overflow: clip does not, it delivers purely the visual clipping. In addition, overflow: clip fully disables programmatic scrolling, which is semantically correct for static containers. overflow-clip-margin allows a controlled exception to the clipping for shadows and focus rings.

Using overflow: clip together with contain: paint correctly gives the browser maximum information for rendering optimizations: paint operations can be confined to the bounding box, enabling partial repainting and compositor layer promotion. In a component-based CSS architecture, the rule is simple: wherever overflow: hidden is only used for clipping, without needing scroll or BFC properties, overflow: clip is the more correct and more performant value.

overflow: clip vs. hidden: the essentials at a glance

No BFC

overflow: clip creates no block formatting context. Margin collapsing and float behavior stay unchanged. More precise than hidden for purely visual clipping.

No scroll

Programmatic scrolling via JavaScript is disabled. The right choice for static containers, overflow: hidden still allows JS scrolling.

overflow-clip-margin

Exclusive to clip: extend the clipping boundary by N px. Box shadows and focus rings can bleed slightly without needing to set overflow: visible.

contain: paint

Combining overflow: clip and contain: paint yields maximum paint isolation. The browser can use cheaper partial repaints and compositor layer promotion.

11. FAQ: CSS overflow: clip vs. hidden

1clip vs. hidden: what is the difference?
Both clip visually. hidden additionally creates a block formatting context. clip does not, it is purely visual clipping without BFC side effects.
2When to use overflow: clip instead of hidden?
When only visual clipping is needed, no scrolling is desired and no BFC is required. Typical cases: image containers, card wrappers with border-radius.
3Does clip create a stacking context?
No. clip behaves like overflow: visible regarding stacking context. No new z-index space, fewer z-index conflicts in complex layouts.
4What is overflow-clip-margin?
Exclusive to clip: extend the clipping boundary by N px. Shadows and focus rings can bleed slightly, overflow: visible is not needed.
5What is a block formatting context?
A layout isolation mechanism: floats do not escape the container, margin collapsing does not take place. overflow: hidden creates a BFC, often unintentionally.
6Browser support for overflow: clip?
Chrome 90+, Firefox 81+, Safari 16+. Over 90% global support in 2026. Fallback: overflow: hidden, visually identical, with BFC side effects.
7Does clip prevent JS scrolling?
Yes, completely. Even element.scrollTop via JavaScript is disabled. overflow: hidden still allows JS scrolling under certain circumstances.
8What is contain: paint?
Paint operations confined to the bounding box. Enables partial repainting and compositor layer promotion. Combined with overflow: clip, maximum paint isolation.
9Independent X and Y axis?
Yes: overflow-x: auto; overflow-y: clip. clip is the only value that avoids the implicit visible to auto rewriting.
10Replace overflow-hidden in Tailwind?
For image clipping and card wrappers, yes. Custom utility or overflow-clip class in Tailwind. Visually identical, without BFC effects on spacing and margin collapsing.