Web design and digital-business ideas grounded in real tasks.

CSS anchor positioning can move a popup when its first position does not fit

A web interface being checked on a laptop and phone.
AI-generated photographic illustration; not documentary photography.

A popup can sit neatly below its button in the middle of a page and spill out of view near the bottom. CSS anchor positioning provides fallback options for that problem. Once the element has an anchor and an initial position, the browser can try another permitted position when the first does not fit.

Give the browser alternatives in an order

MDN’s position-try-fallbacks reference describes an ordered set of alternatives. Built-in tactics can flip a placement along an axis, while named options can supply a more specific arrangement. The browser evaluates these when the positioned element overflows its relevant containing area.

MDN’s guide to fallback options and hiding explains how this fits with the rest of anchor positioning. A fallback declaration does not establish the anchor relationship by itself. Start with a working anchored element before trying to solve its edge cases.

Test the content that actually causes trouble

Create a small demonstration with the same trigger placed near each edge of the available space. Use the real popup content, then try a longer translated label or an additional line. A short placeholder can fit in places where the finished interface cannot.

Record which placement you intend to prefer. If below the trigger is the normal choice and above it is the next best choice, test those positions deliberately. A fallback that technically fits may still obscure the control or information the user needs.

Repeat the check with browser zoom and a narrow viewport. Also test inside the actual scrolling container used by the page, rather than only on an otherwise empty document. The useful result is a popup whose position remains understandable as the layout changes.

Layout does not finish the component

Positioning the box is only one part of building a usable tooltip, menu or popover. Keyboard behaviour, focus, dismissal and the relationship between the trigger and content still need the appropriate component design. Test the browsers your audience uses and retain a workable layout where a feature is unsupported.

Keep a screenshot of each edge case with the browser version and content used. That gives future changes a concrete comparison, especially when a seemingly harmless copy edit makes the popup wider or taller.