Position a CSS popover with anchor positioning

8 steps · about 2 h 34 min · Intermediate

  1. Understand anchor positioning (guide, MDN Web Docs, 30 min)

    See how an anchor and positioned element form a relationship without JavaScript geometry.

  2. Name the trigger as an anchor (reference, MDN Web Docs, 15 min)

    Expose the reference element through a stable CSS anchor name.

  3. Bind the popover to its trigger (reference, MDN Web Docs, 15 min)

    Select which named anchor controls the positioned element.

  4. Place edges relative to the anchor (reference, MDN Web Docs, 20 min)

    Compute inset positions from meaningful anchor sides instead of viewport coordinates.

  5. Choose an initial placement area (reference, MDN Web Docs, 18 min)

    Express a readable relationship such as below and centered without manual transforms.

  6. Declare fallback placements (reference, MDN Web Docs, 20 min)

    Give the browser alternatives when the preferred position would overflow.

  7. Define a custom fallback option (reference, MDN Web Docs, 18 min)

    Adjust multiple positioning properties together for a constrained viewport.

  8. 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.