Native HTML Overlays: Dialog, Popover, Anchor in 2026

Native HTML Overlays: Dialog, Popover, Anchor

The native trio — dialog, Popover API, and CSS Anchor Positioning — can replace tens of kilobytes of Floating UI and Radix dependencies with native HTML, a few CSS declarations, and little JavaScript.

The trio of <dialog>, the Popover API, and CSS Anchor Positioning now does what Floating UI, Headless UI, and Radix have been doing for years — modal management, light dismiss, focus trap, top-layer rendering, and collision-aware placement — natively and accessibly, with little or no JavaScript for the structural layer. As of October 2026, <dialog> is Baseline Widely available (since September 2024), the Popover API is Newly available (since January 2025), and Anchor Positioning ships in all three engines but is still Limited availability in Baseline terms and an Interop 2026 focus area. This guide gives you the syntax, the composition patterns for typical UI primitives, and a migration plan that retires tens of kilobytes of overlay-library bundle without changing your design-system API.

The accumulated cost of the JavaScript overlay layer

Many frontend applications have shipped two libraries to handle overlays, plus framework glue. Floating UI (or its predecessor Popper.js) handled positioning math — placement, collision detection, flipping, shifting. Headless UI or Radix UI handled the accessibility behavior — focus trap, ARIA wiring, Escape handling, scroll lock. The framework itself contributed portal helpers, useEffect lifecycle plumbing, and the integration glue between the two.

Combined, these dependencies could add tens of kilobytes of JavaScript per page — for behavior the platform has finally standardized. As one reference point, Bundlephobia reports Floating UI's DOM package at about 21 KB minified (about 8 KB gzipped) as of October 2026, before framework bindings; accessibility primitive libraries add their own weight per component. The totals vary widely by stack and tree-shaking, so measure your own bundle rather than relying on a published range. None of it was wasted work in its time, but much of it is now redundant.

The hidden cost was implementation drift. Libraries can implement focus trapping differently — for example, which elements count as focusable and what happens when focus is lost. Each handles ARIA wiring with its own conventions — aria-modal versus inert on the rest of the page, which roles get applied automatically, how labels are associated. Migrations between libraries (Headless to Radix, Reach to Headless) could introduce subtle accessibility regressions because the source library and target library disagreed on edge-case behavior.

Native HTML elements ship the same behavior in the engine, accessible by default, and free of bundle weight. The behavior is defined in the HTML specification rather than in each library, and cross-engine differences are tracked through Interop, so audits can target one behavior instead of several library conventions.

The migration is incremental. You can replace one primitive at a time, keep the design system's public API stable, and measure the bundle delta after each step. The work is mechanical once the patterns are understood.

<dialog> — modal and non-modal

The <dialog> element handles modal and non-modal dialogs as a first-class HTML primitive. It became Baseline Newly available in March 2022 and Widely available in September 2024, and <dialog> was an Interop 2022 focus area.

The two methods that matter are showModal() and show(). showModal() opens the dialog in the top layer — a per-document rendering layer above all stacking contexts, so z-index conflicts no longer apply — with a focus trap and an automatic ::backdrop pseudo-element. show() opens the dialog without a focus trap, useful for non-modal panels that share keyboard focus with the surrounding page.

html
<dialog id="settings">
  <form method="dialog">
    <h2>Settings</h2>
    <!-- form fields -->
    <button value="cancel">Cancel</button>
    <button value="save">Save</button>
  </form>
</dialog>
<button onclick="settings.showModal()">Open settings</button>

The <form method="dialog"> pattern is the idiomatic close mechanism. Submitting the form closes the dialog and the submit button's value becomes the dialog's returnValue. No JavaScript event handler is required for the close path.

The closedby attribute (and the corresponding HTMLDialogElement.closedBy property) controls dismiss behavior declaratively. closedby="any" allows Escape (a platform close request), outside-click, and your own close controls; closedby="closerequest" drops outside-click; closedby="none" allows only your own close controls. Where it is supported, this replaces the JavaScript event-listener patterns previously needed for outside-click dismiss. As of October 2026, closedby ships in Chrome and Edge 134 and Firefox 141 but not in Safari, so it is Limited availability; keep a JavaScript outside-click fallback wherever Safari traffic matters.

ARIA semantics are handled automatically. The engine sets role="dialog" on the element, applies modal semantics when showModal() is used, and announces the dialog correctly to screen readers. Manual aria-modal management is no longer necessary; the engine's behavior is the spec.

Animating the dialog open and close uses @starting-style to set the values the dialog transitions from every time it opens, plus display and overlay in the transition list with transition-behavior: allow-discrete. Transitioning display keeps the dialog visible (for example, display: block) for the duration of the transition, and transitioning overlay defers the dialog's removal from the top layer until the closing transition completes. As of October 2026, overlay ships only in Chromium (Chrome and Edge 117), so Firefox and Safari do not defer the removal this way. The ::backdrop pseudo-element is animatable independently, so the backdrop fade and the dialog slide can be choreographed in pure CSS.

Popover API — declarative overlays without focus trap

The Popover API handles overlays that should not trap focus — dropdowns, tooltips, menus, command panels, notification toasts. Desktop engines shipped it between May 2023 and April 2024, and it became Baseline Newly available in January 2025, when Safari on iOS 18.3 completed support. As of October 2026 it is still Newly available, with Widely available projected for July 2027. It was an Interop 2024 focus area.

The core mechanism is the popover attribute on any HTML element. popover="auto" opts the element into the auto group, which provides light dismiss — Escape, outside-click, and opening another auto popover all close it. Auto popovers are also mutually exclusive: opening a new auto popover automatically closes any other open auto popover that is not its ancestor.

html
<button popovertarget="menu">Menu</button>
<div id="menu" popover>
  <button>Profile</button>
  <button>Settings</button>
  <button>Sign out</button>
</div>

popover="manual" opts out of light dismiss, for popovers that need explicit close logic — a notification toast that should dismiss only after the user acknowledges, or a popover whose lifecycle is tied to a network operation.

The declarative wiring uses popovertarget and popovertargetaction. A <button popovertarget="id"> opens, closes, or toggles the popover with the given ID; the optional popovertargetaction="show", "hide", or "toggle" makes the action explicit. No JavaScript event handlers are required for the open / close path.

Like <dialog>, popovers render in the top layer above all stacking-context boundaries. The z-index wars and portal-helper patterns of the JavaScript overlay layer are no longer necessary; the engine puts the popover above everything else automatically.

The distinction from <dialog> is the focus trap. Popovers do not trap focus; they are right for dropdowns, menus, tooltips, and any UI where the user's focus should follow them through the popover and out the other side. Modal dialogs that need to capture all interaction until dismissed should use <dialog> with showModal(). Mistaking the two — using popover for a settings modal, or using a modal dialog for a dropdown — produces accessible-but-frustrating UX.

CSS Anchor Positioning — placing overlays relative to triggers

CSS Anchor Positioning replaces the JavaScript positioning math that Floating UI and Popper.js used to do — measuring the trigger's bounding box, computing available space, choosing a placement, handling collision flips. As of October 2026, all three engines ship the core of the specification (Chrome and Edge since 125, Firefox since 147, Safari since 26), but Baseline still classes it as Limited availability because only Safari 27 implements the full feature set (caniuse). It is an Interop 2026 focus area, carried over from Interop 2025, which means it is part of the year's coordinated effort to increase its interoperability across browsers — though that does not set a date for Baseline status.

The basic pattern uses anchor-name on the trigger and position-anchor on the popover, plus the anchor() function in inset properties:

css
.menu-button {
  anchor-name: --menu-anchor;
}
.menu {
  position: fixed;
  position-anchor: --menu-anchor;
  top: anchor(bottom);
  left: anchor(start);
}

This places the menu's top edge at the button's bottom edge and the menu's left edge at the button's start edge — the standard dropdown placement. The anchor() function takes the side of the anchor element to align against (top, bottom, start, end, center).

The anchor-size() function makes the popover's size relative to the anchor:

css
.menu {
  width: anchor-size(width);
}

This gives a dropdown menu the same width as its trigger button — a common pattern that previously required JavaScript width-measurement.

Collision handling uses position-try-fallbacks, which declares alternative placements when the primary position would clip the popover off-screen:

css
.menu {
  position-try-fallbacks: flip-block, flip-inline;
}

The engine tries the primary placement first, then each fallback in order until one fits in the viewport. This replaces Floating UI's flip() middleware with declarative CSS, but not shift() or offset(). Shift-like behavior comes from position-area instead: when the popover is placed with position-area and overflows its inset-modified containing block but would still fit within its original containing block, its default alignment shifts it to stay within the original containing block. The position-area shorthand provides a simpler interface for common placements: position-area: bottom span-all places the popover in the row below the anchor and spans all three columns of the position-area grid, which reaches across the full width of the popover's containing block, not just the anchor's width. To match the anchor's width, combine a placement with width: anchor-size(width).

Composing the three for typical patterns

The trio composes naturally for the standard UI primitives.

A modal dialog — settings panel, confirmation dialog, full-screen mobile overlay — uses <dialog> with showModal(). No popover, no anchor positioning. The focus trap is the load-bearing behavior.

A dropdown menu — the most common popover use case — combines popover for dismiss behavior with anchor positioning for placement. The trigger button has anchor-name and popovertarget; the menu is a popover element with position-anchor and a top: anchor(bottom) placement. No <dialog>, no JavaScript, no Floating UI.

A tooltip is a popover="manual" with anchor positioning. The manual mode is necessary because tooltips need hover and focus triggers (which popovertarget does not provide — it activates on click only), so a small JavaScript event listener calls tooltip.showPopover() on hover and hidePopover() on leave. The earlier CSS Toggles proposal was abandoned; the current declarative direction is interest invokers (the interestfor attribute) paired with popover="hint". As of October 2026, interest invokers ship only in Chromium (since 142) and popover="hint" ships in Chromium and Firefox but not Safari, so both are Limited availability and the event listener stays for now. Click-driven toggles, by contrast, already have a Baseline answer in invoker commands (command and commandfor), Newly available since December 2025.

A command palette — a focus-trapping search-and-action overlay — uses <dialog> with showModal() for the modal shell and JavaScript for arrow-key navigation between command items. The dialog handles focus trap and Escape; the rest is application-specific keyboard behavior.

A date picker is a hybrid: full-screen <dialog> on mobile (where the picker should occupy the screen and trap focus), and a popover with anchor positioning on desktop (where the calendar dropdown sits below the input field). The same component can render both modes based on viewport.

What still requires JavaScript

The native APIs handle the structural primitives, but UI-specific behavior still needs application code.

Hover-triggered popovers need event listeners. popovertarget activates on click only; hover and focus triggers require a small handler that calls showPopover() on mouseenter / focus and hidePopover() on mouseleave / blur. The amount of JavaScript is a few lines, not a library, but it is not zero.

Arrow-key navigation within a popover — moving between menu items, listbox options, autocomplete suggestions — is application logic. The popover itself does not know that its children form a menu; that semantic comes from the application. Roving tabindex or aria-activedescendant patterns still apply, just inside a popover instead of a portal.

Custom dismiss reasons — popovers that should close only when a network operation completes, or only when the user explicitly confirms — use popover="manual" with explicit hidePopover() calls in the application's own logic.

Coordinating state across multiple popovers beyond the auto group's mutual-exclusion — for example, a notification system where exactly two toasts can be visible at once — requires application coordination. The platform handles the structural layer; the product layer handles its own rules.

Coordinating with framework router lifecycles is a thin wrapper. In a single-page app, opening a dialog on route change uses the same showModal() call inside the route component's mount effect; closing on route change uses close() in the unmount effect. Because the dialog is an ordinary DOM node, it fits inside framework rendering like any other element; test it with your framework's concurrent and suspense features before relying on it.

Migration strategy

The safe migration order is Dialog first, then Dropdown / Menu, then Tooltip — this order tends to keep behavioral surprises small, because each step builds on the previous one.

Step one is replacing the design-system Dialog component's internals. The public API stays — <Dialog open onClose={...}>...</Dialog> continues to work — but the internal implementation becomes a thin wrapper around <dialog> with showModal() and close() calls. Portal helpers, focus-trap libraries, and scroll-lock helpers come out of the dependency tree at this step.

Step two is the design-system Dropdown / Menu component. The internal implementation switches to a popover element with anchor positioning. Floating UI comes out of the dependency tree. The migration here is more invasive than Dialog because the placement math was likely customized; the equivalent CSS Anchor Positioning declarations need to be derived from the existing Floating UI configuration.

Step three is Tooltip. Popover with popover="manual" plus anchor positioning, plus the small event-listener wrapper for hover and focus. This is the smallest migration but exercises the manual popover mode and the hover-event pattern, which are the patterns most likely to recur in other components.

Testing each migration with NVDA on Windows and VoiceOver on macOS before rollout is non-negotiable. The native behavior is correct and accessible, but specific announcement patterns can differ from library implementations, and some QA test scripts may need adjustment.

After all three primitives are migrated, the Floating UI / Headless UI / Radix dependencies can come out of package.json. Measure the bundle delta on your own stack; the reduction in overlay-related JavaScript depends on which libraries and middlewares were in use, and can reach tens of kilobytes.

What this changes about compatibility decisions

The native overlay trio illustrates this topic's broader thesis. Compatibility work in 2026 is not about engine quirks; it is about reading platform availability and choosing the right adoption window.

As of October 2026, <dialog> is Widely available — adopt without polyfills, retire fallback code, write the design-system primitive once. Popover is Newly available — adopt it once your audience data confirms that the remaining older-browser share is acceptable. Anchor Positioning is Limited availability and on the Interop dashboard — adopt for visual placement, fall back to a JavaScript-free static placement when @supports (anchor-name: --x) is false, and watch the Interop convergence signal.

The trio together can replace tens of kilobytes of dependency bundles with a few CSS declarations and a small amount of application JavaScript. Accessibility behavior shifts from library-author responsibility to engine-author responsibility. Design-system component APIs become smaller because the props for portal targets, focus-trap configuration, and z-index escapes are no longer needed.

Migration priorities for the next planning cycle

  • Pick one design-system primitive (Dialog is the easiest first migration) and replace its internal portal + focus-trap + scroll-lock with a thin wrapper around <dialog> and showModal()
  • Keep the public component API stable so consumers do not change call sites; ship the migration as an internal refactor
  • Test focus management, screen-reader announcement, and Escape behavior with NVDA + VoiceOver before merging
  • Repeat with Dropdown / Menu using popover plus CSS Anchor Positioning; remove Floating UI when the migration completes
  • Repeat with Tooltip using popover="manual" plus anchor positioning plus a small hover / focus event-listener wrapper
  • Remove the overlay-library dependencies from package.json and report the bundle delta in the PR description
Project Inquiry