Position a CSS popover with anchor positioning
8 steps · about 2 h 34 min · Intermediate
- Understand anchor positioning (guide, MDN Web Docs, 30 min)
See how an anchor and positioned element form a relationship without JavaScript geometry.
- Name the trigger as an anchor (reference, MDN Web Docs, 15 min)
Expose the reference element through a stable CSS anchor name.
- Bind the popover to its trigger (reference, MDN Web Docs, 15 min)
Select which named anchor controls the positioned element.
- Place edges relative to the anchor (reference, MDN Web Docs, 20 min)
Compute inset positions from meaningful anchor sides instead of viewport coordinates.
- Choose an initial placement area (reference, MDN Web Docs, 18 min)
Express a readable relationship such as below and centered without manual transforms.
- Declare fallback placements (reference, MDN Web Docs, 20 min)
Give the browser alternatives when the preferred position would overflow.
- Define a custom fallback option (reference, MDN Web Docs, 18 min)
Adjust multiple positioning properties together for a constrained viewport.
- Preserve a non-anchored baseline (reference, MDN Web Docs, 18 min)
Detect the enhancement only when necessary so unsupported browsers still show an operable popover.