Skip to content
IndexRequest a UIAboutContact

Anchored Popover

A popover with an arrow that flips above or below to fit and closes on Escape or outside click.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build an anchored popover component. A trigger button "Details" opens a 220 pixel wide card with a small arrow pointing at the button. The card contains a title, two lines of text and a link button. It prefers to open below but flips above when there is not enough space; two small buttons let the user prefer Top or Bottom to test. Close on Escape, on outside click and when the trigger is pressed again; return focus to the trigger. aria-expanded and aria-controls on the trigger, role dialog without modal on the card. Subtle shadow, 12 pixel radius, 160 millisecond fade and slide with a prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.

About this pattern

Definition

A popover is a small floating panel anchored to a trigger. Unlike a tooltip it can hold interactive content and opens on click; unlike a modal it does not block the page.

Purpose & UX principles

  • Use it for secondary details, quick settings or short forms that relate to one control.
  • Open on click or Enter, close on Escape, outside click or when focus leaves.
  • Position it automatically to stay on screen, with an arrow that points to the trigger.

Interaction states

  • Closed, open above, open below. Placement buttons let you prefer top or bottom; the popover flips if there is no space.

Motion specification

  • Popover fades and slides 6px toward its final position over 160ms.
  • Reduced motion: fade only.

Responsive behaviour

  • Width up to 240px, limited to the viewport minus 16px margins; on very small screens consider a bottom sheet instead.
  • Flip to the side with more room.

Code

HTML
<div class="bx"><div class="anch" id="anch"><button id="tg" type="button" aria-expanded="false" aria-controls="pop">Details</button><div class="pop" id="pop" role="dialog" aria-label="Details" hidden><i class="ar"></i><b>Billing period</b><p>Billed on the 1st.</p><a href="#" onclick="return false">Change plan</a></div></div>
<div class="pre" id="pre" role="group" aria-label="Preferred placement"><button data-p="top" aria-pressed="false">Prefer top</button><button data-p="bottom" aria-pressed="true">Prefer bottom</button></div></div>

Related patterns

Dropdown Menu

↗
Dropdown MenuOverlays & Dialogs

Tooltip

↗
TooltipFeedback & Notifications

Modal Dialog

↗
Modal DialogOverlays & Dialogs