How to Configure Strict CSS Position-Visibility in Google Chrome

Contextual tooltips, hover indicators, and anchored callout menus frequently cause layout glitches when their associated trigger elements scroll out of the visible viewport. Historically, detecting when an anchor scrolled off-screen required registering JavaScript IntersectionObserver listeners or tracking scroll offset events. Within Google Chrome, the modern CSS Anchor Positioning specification introduces position-visibility, empowering authors to declaratively control anchored element rendering based on anchor box visibility.

Understanding Position-Visibility States

The position-visibility property provides three deterministic operational values:

  • always (default): The anchored element remains displayed at its computed coordinates regardless of whether the reference anchor is visible or clipped by an overflow container.
  • anchors-visible: The anchored element is conditionally rendered only when the reference anchor box is at least partially visible within its scrollport. If the anchor is completely clipped by an ancestor scroll container, the anchored element hides automatically.
  • no-overflow: The anchored element hides automatically if it overflows its containing block or viewport boundary and cannot be accommodated by candidate position-try-fallbacks.

Configuring Strict Visibility Rules

To ensure that floating contextual toolbars or hover cards vanish cleanly when their reference row scrolls outside a scrollable data grid, apply position-visibility: anchors-visible:

/* Anchor reference inside scrollable grid row */
.data-table-row-action {
  anchor-name: --active-row-trigger;
}

/* Tethered floating action bar */
.contextual-floating-action-bar {
  position: fixed;
  position-anchor: --active-row-trigger;
  top: anchor(bottom);
  left: anchor(center);
  transform: translateX(-50%);
  margin-top: 6px;
  
  /* Automatically hides when row scrolls out of view */
  position-visibility: anchors-visible;
  
  background-color: #1e293b;
  color: #f8fafc;
  padding: 8px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

When the user scrolls the data grid and the active row leaves the container viewport, Chrome hides the action bar instantly without executing a single line of JavaScript.

Combining No-Overflow with Dynamic Fallbacks

For dialogs and popovers that must never partially clip against the viewport perimeter, configure position-visibility: no-overflow alongside position-try-fallbacks:

.strict-modal-popover {
  position: fixed;
  position-anchor: --modal-anchor;
  inset-area: bottom span-right;
  position-try-fallbacks: flip-block, flip-inline;
  position-visibility: no-overflow;
}

If neither the primary inset nor the fallback orientations can fit the popover within the viewport bounds, the browser suppresses the popover automatically, preventing ugly partial clipping across constrained mobile screens.

Auditing Position-Visibility in Chrome DevTools

Google Chrome DevTools provides visual feedback for conditional anchor visibility:

  1. Open DevTools (F12) and select the Elements panel.
  2. Inspect an anchored element styled with position-visibility.
  3. Scroll the document container so that the anchor leaves the visible scrollport.
  4. Notice that DevTools dims the anchored element DOM node or reflects the computed visibility suppression in the layout tree.
  5. In the Computed styles panel, verify that position-visibility resolves accurately to anchors-visible or no-overflow.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.