modern-web-guidance
Search tool for modern web development best practices. MANDATORY: Execute FIRST for all HTML/CSS and clientside JS tasks. Do NOT skip — web APIs evolve rapidly and training weights contain obsolete patterns. Trigger immediately for: modals/dialogs/popovers, tables, dark mode, anchor positioning, container queries, view transitions, scroll-driven animations, parallax/reveals, forms, validation, autofill, accessibility, custom selects, scrollbars, CWV (LCP, INP, CLS), content-visibility, fetch pri
Install
npx skills add https://github.com/GoogleChrome/modern-web-guidance --skill modern-web-guidanceOverflow Clipping Control
While overflow: hidden is a "blunt instrument" that almost always clips content strictly at the padding-box, overflow: clip combined with overflow-clip-margin provides the "scalpel" for fine-grained layout control across block containers.
Specify exactly where clipping occurs with overflow: clip and overflow-clip-margin. You can align the boundary precisely with inner box-model edges or extend the clipping boundary beyond the element's box by a specified offset (a safety margin). This modern approach is highly performant and eliminates the legacy requirement of adding extra wrapper containers with custom padding and negative margins just to let visual effects (like prominent child element shadows) render unclipped.
Replaced elements (<img>, <video>, <canvas>, etc.) default to overflow: clip and overflow-clip-margin: content-box, giving you control to cleanly contain images that use object-fit or border-radius.
How to Implement
- Apply
overflow: clip: Ensure the target element hasoverflow: clipenabled. Settingoverflow: clipis mandatory on block layout containers foroverflow-clip-marginto take effect. Ifoverflowis set tohidden,auto, orscroll, theoverflow-clip-marginproperty is ignored by the browser.overflow: clipprevents all scrolling (both user-initiated and programmatic via JavaScript). - Align to a Box-Edge: Use keywords to precisely align the clipping boundary to inner box-model edges:
content-box: Clips content exactly where the content area begins, leaving the padding area completely clean. Content stops right at the padding's edge. Excellent for nested layout modules.padding-box(Default): Clips content at the inner edge of the border.border-box: Clips content at the outer edge of the border, allowing content to sit under or partially overlap a translucent border.
- Define a Specified Offset (The Bleed): Provide a length value (e.g.,
15pxor5px) to create a safety zone before cutting pixels. This allows prominent child element shadows to render unclipped past the boundary edge without expanding layout geometry. - Combine Box-Edge and Offset: Specify both a box edge and a length offset simultaneously (e.g.,
content-box 15px) to offset from a specific box edge.
Example Code
The following examples demonstrate dynamic container layout controls, showcasing automated inner content curve nested framing and child element shadow protection alongside progressive enhancement fallbacks.
Block Containers: Nested Rounded Curves
- Apply
overflow-clip-margin: content-boxto a parent container with rounded corners and custom padding. - Apply similar rounded corners on inner child media and footer components along the concentric inner content box boundary, solving awkward nesting curves without custom
calc()logic.
Block Containers: Child Element Shadow Bleed
- Apply
overflow: clipand define an extendedoverflow-clip-marginlength offset to create a visible safety zone permitting the child's shadow to render unclipped outside the parent container without altering layout geometry. Without this, the child's shadow is clipped at the parent's boundary.
Strategic Implementation & Best Practices
- DO apply
overflow: clipon target elements when utilizingoverflow-clip-margin, as settingoverflowstrictly toclipis mandatory on standard block layout containers to activate custom or inner curved clip margins. - DO set
overflow-clip-margin: content-boxon padded containers with rounded corners to automatically clip unrounded internal child elements into mathematically perfect nested border curves without manual padding subtraction logic. - DO configure
overflow-clip-marginwith a specified length offset when applying external visual effects (likefilter: drop-shadow()) to prevent sharp bounding box truncation without altering or expanding layout geometry. - DO NOT apply
overflow: clipif the container requires programmatic scroll manipulation via JavaScript or serves as the immediate layout context forposition: stickyelements, asclipcompletely disables scrolling.
Fallback Strategies
Baseline status for overflow: clip: Widely available. It's been Baseline since 2022-09-12. Supported by: Chrome 90 (Apr 2021), Edge 90 (Apr 2021), Firefox 81 (Sep 2020), and Safari 16 (Sep 2022).
Browser support for overflow-clip-margin: Limited availability. Supported by: Firefox 148 (Feb 2026). Unsupported in: Chrome, Edge, and Safari.
For target environments lacking native support for overflow: clip or overflow-clip-margin, progressive enhancement fallback strategies depend directly on the visual intent:
- Fallback to
overflow: hiddenas the base experience to guarantee core boundaries are maintained. - Fallback to
overflow: visibleon elements where drop-shadows or external corner badges must not be truncated.