We have spent the better part of a decade outsourcing our layout logic to JavaScript. If you wanted a tooltip to stay pinned to a button, a dropdown to follow a menu item, or a sliding “active” highlight to track a navigation bar, you reached for Popper.js or Floating UI. It was a necessary evil. We accepted the bundle size bloat and the main-thread layout thrashing because CSS simply didn’t have a way to say, “Put this element right here, relative to that other element over there.”
In her recent exploration of “Connected Buttons,” Ania Kubów highlights a tectonic shift in how we approach these interfaces. We are moving away from the getBoundingClientRect() era and into the era of the CSS Anchor Positioning API. This is not just a new property; it is a fundamental rethinking of the relationship between elements in the DOM.
The Technical Mechanism: How Anchoring Actually Works
The core of the “connected” button effect relies on two distinct roles: the Anchor and the Target. Traditionally, to make a background highlight “slide” between buttons, we had to calculate offsets in JavaScript and apply transform: translateX() manually. With Anchor Positioning, the browser handles the geometry.
To implement this, you first designate your buttons as anchors. Each button gets a unique identifier using the anchor-name property. It is important to note that these names must follow the “dashed-ident” format, meaning they require a double dash prefix, similar to CSS custom properties (e.g., anchor-name: --button-1).
The “connected” piece usually a pseudo-element or a separate div acting as a highlighter becomes the target. By using position: absolute and position-anchor: --button-1, you tether the highlighter to that specific button. The magic happens when you update the position-anchor value on hover or focus. The browser perceives this as a layout change and can transition the position smoothly if you pair it with the right transition properties.
Beyond Simple Tooltips: The Power of Inset-Area
One of the most misunderstood aspects of this new API is how we define where the connected element sits. In the past, we relied on top, left, and complex calc() functions. The modern approach uses inset-area (often referred to as position-area in evolving specifications).
Imagine a 3×3 grid centered on your anchor button. inset-area allows you to place the connected element in any of these nine regions or spans of regions using intuitive keywords like top, bottom left, or span-all. When Ania demonstrates connecting buttons, she is leveraging this grid to ensure the highlighter perfectly aligns with the padding and margins of the trigger element without a single line of coordinate math.
The Performance Trade-off: Main Thread vs. Layout Engine
The industry is currently obsessed with “Core Web Vitals,” and for good reason. Every kilobyte of JavaScript used for positioning is a kilobyte that blocks the main thread. By moving the “connected” logic to the CSS Anchor Positioning API, we see a massive reduction in CPU usage. In some stress tests, switching from JS-based positioning to native CSS anchoring reduced CPU activity during scroll and resize events from 50% to under 5%.
The reason is simple: when the browser’s layout engine handles the positioning, it doesn’t have to wait for the JavaScript execution loop. It knows exactly where the anchor is during the layout phase and can place the target accordingly. This eliminates the “jitter” or lag often seen in JS tooltips where the box trails slightly behind the button during a fast scroll.
Interoperability and the “Bleeding Edge” Reality
While the technical advantages are clear, we have to address the elephant in the room: browser support. As of late 2024 and moving into 2026, we are seeing Chrome and Edge lead the charge with full support from version 125 onwards. Firefox and Safari have been slower to implement the full spec, particularly the more advanced @position-try rules which allow for smart fallbacks (e.g., “if there is no room on the top, move the tooltip to the bottom”).
For production-ready apps, this means we cannot fully delete our JavaScript fallbacks just yet. However, we can use “Progressive Enhancement.” We can ship the CSS-native version for modern browsers and keep a lightweight polyfill or basic absolute positioning for legacy ones.
Critical Perspective: Is It Over-Engineered?
Some skeptics argue that anchor-name adds unnecessary complexity to our stylesheets. Why give every button a name when we could just use a container? The answer lies in the Top Layer.
Modern web UIs often use the popover attribute or the <dialog> element. These elements live in a “top layer” that sits above all other z-index stacks. Historically, positioning a top-layer popover relative to a button in the deep DOM was a nightmare. Anchor Positioning is the only native CSS solution that can bridge this gap, allowing a top-layer element to “know” the coordinates of an element buried deep inside a flexbox or grid.
The Future of Design Systems
This shift will fundamentally change how we build component libraries like Shadcn/UI or Radix. Instead of shipping massive logic for “Edge Detection” and “Collision Handling,” these libraries will eventually become thin wrappers around @position-try and inset-area.
We are moving toward a declarative UI where we describe the intent of the connection (“stay next to this button”) rather than the mechanics (“calculate x + width + offset”). Ania’s tutorial on “Connected Buttons” is more than a styling trick; it is a preview of a world where JavaScript is no longer the glue that holds our layouts together.
