CSS Tools
Advertisement
Google AdSense Placement Area
Responsive Ad Unit
Back to All Tools/Modern CSS/CSS Anchor Positioning Studio
Modern CSS Spec 2024• Chrome 125+ / Safari 18+

CSS Anchor Positioning Studio

Tether floating UI elements directly to trigger anchors without heavy JavaScript position calculation libraries.

/* CSS Anchor Positioning Specification */
.anchor-button {
  anchor-name: --my-anchor;
}

.tooltip-popover {
  position: absolute;
  position-anchor: --my-anchor;
  position-area: bottom right;
  margin: 12px;
  position-try-fallbacks: flip-block;
  
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  padding: 12px 16px;
  color: #ffffff;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

Position Parameters

Offset Margin12px
Position Try Fallbacks
Anchor Target (--my-anchor)
Tethered Popover

Area: bottom right

Advertisement
Google AdSense Placement Area
Responsive Ad Unit

Comprehensive Guide to CSS Anchor Positioning API (W3C Specification)

Technical documentation & best practices for declarative floating UI tethering without JavaScript

1. Why CSS Anchor Positioning Matters

For over a decade, building responsive floating interfaces—such as tooltips, dropdown menus, popovers, and contextual dialogs—required heavy JavaScript coordinate calculations. Popular libraries like Popper.js or Floating UI listened to scroll and resize events, measured element dimensions with getBoundingClientRect(), and applied inline style coordinates to the DOM.

This JavaScript-driven approach introduces significant drawbacks: increased bundle size, layout thrashing that impairs smooth scrolling, and potential position lag during fast gestures. The CSS Anchor Positioning API shifts floating calculations into the browser's native CSS engine, allowing overlay elements to bind contextually to target anchors directly on the hardware-accelerated compositor thread.

2. Core Syntax & Anatomy

The specification relies on four primary declarative CSS primitives:

  • anchor-name: --my-anchor;Applied to the trigger element (e.g., button or link) to register a named anchor identifier across the scoped DOM scope.
  • position-anchor: --my-anchor;Declared on the floating target (tooltip/popover) to tether its position relative to the named anchor.
  • position-area: bottom right;An intuitive 3x3 grid shorthand defining relative placement around the anchor without manual math (e.g., top left, bottom center, inline-end).
  • anchor(edge, offset) & position-try-fallbacksThe anchor(bottom) function grants fine-grained inset mapping, while position-try-fallbacks: flip-block provides automatic collision flipping when elements hit viewport bounds.

3. Native Integration with HTML Popover API

The full power of CSS Anchor Positioning is unlocked when paired with the native HTML5 popover attribute and <dialog> elements. Popover elements automatically promote to the browser's Top Layer—eliminating z-index stacking context issues. Combining HTML popovertarget with CSS position-anchor creates fully accessible, high-performance floating UI components written with zero JavaScript overhead.

Native Browser Compatibility Table

Current engine support status for the CSS Anchor Positioning API

Browser / EngineSupport StatusMinimum VersionImplementation Notes
Google Chrome (Blink)Full Nativev125+ (May 2024)Ready for production deployments
Microsoft Edge (Blink)Full Nativev125+ (May 2024)Full compliance with latest W3C specs
Apple Safari (WebKit)Full NativeSafari 18+ (iOS 18/macOS)Supports position-area & anchor() syntax
Mozilla Firefox (Gecko)In DevelopmentNightly / FlagEnabled via layout.css.anchor-positioning.enabled

Technical Architecture Specifications

In-depth exploration of position recalculation and fallback routing

Advertisement
Google AdSense Placement Area
Responsive Ad Unit