Overlay Avoidance
How overlay components handle limited space
Overlay avoidance means marking out the room first, then placing the overlay inside it: four rules (flip and cap menus, pinned dialog bars, 8-way tooltips with hysteresis, clear fixed bars) and a live demo.
Tooltips, menus, dialogs and other overlays hold content of varying length, and the size of the app window or browser viewport is never fixed either: a detail AI easily misses when it generates an interface. An overlay that only opens in one fixed direction gets clipped by the viewport, or covers key controls, as soon as its trigger nears an edge, sits at the bottom of a long list or scrolls under a sticky header. The reliable approach is to mark out the overlay’s room first: the viewport inset by 16px on every side, and, for non-modal overlays inside the page, minus the sticky header and any fixed bottom bar as well. Render overlays at the top level through a portal so no parent container clips them, and work out the position again whenever the overlay opens, the page scrolls, the window resizes or its own size changes.
Flip it when it doesn’t fit, cap it when it’s too tall
A menu opens 8px below its trigger by default. When there’s too little room below and enough above, it should flip and open upward; a cascading submenu that doesn’t fit on the right flips to the left in the same way, and the starting point of the opening animation (transform-origin) moves to the side nearest the trigger too. If it still overflows sideways after flipping, shift it along the viewport edge back into the safe area; if the menu is still taller than the room on its side, cap the container’s maximum height to that room, let it scroll inside, and fade out the cut-off edge to hint that there’s more below. And if the user scrolls the page with the cursor outside an open menu, their attention has gone back to the main view: the menu should fade out and close at once.
- Use it for: dropdown menus, context menus, cascading submenus, selects
- Values: 16px from the viewport edge, 8px from the trigger; flip, then shift, then cap the height and scroll; fade out at once when the page scrolls outside the menu
Keep a dialog’s header and footer in view
When a dialog holds long content and simply grows to fit it while staying centered, the title row and the bottom action row get pushed out of the viewport: users lose track of the context and can’t find the confirm button. Cap the dialog’s height to the safe height of the viewport, keep the title bar and the action bar fixed, let only the content between them scroll, and show a 1px divider once the content scrolls under the title. If a case often has a lot of content, use a drawer instead of a dialog: a side drawer on desktop, and on mobile a full-width bottom sheet that extends upward.
- Use it for: dialogs with long lists, settings panels, form dialogs, terms to accept
- Values: 16px top and bottom, the title row and action row fixed, a 1px divider under the title once the content scrolls; a side drawer, or a full-width sheet on mobile, when the content is often long
Tooltips that switch sides, cursor tips with hysteresis
When a tooltip overflows an edge of the viewport, flip it to the other side; if it only overflows a little near one side, you can also shift it along the edge back into the room, with its arrow always pointing at the center of the trigger. A tooltip with an arrow can have 8 placements ready (top, bottom, left, right and the four corners) and pick the best one by the room left to each edge. A cursor tip that follows the pointer on a chart sits below and to the right of the cursor by default, fully clear of the cursor itself; near the right edge it moves to the cursor’s left, and on the way back it returns to the right only once the cursor is 24px further in than where it switched. This hysteresis keeps the tip from jumping back and forth while the cursor rests near the boundary. For where tooltips, cursor tips and drawers each fit, see 009 Choosing between tooltips, popovers, drawers, and dialogs.
- Use it for: tooltips on icon buttons and avatars, chart readout tips, info cards that follow the cursor
- Values: 8 placements chosen on the fly for tooltips with an arrow, the arrow aimed at the trigger’s center after a shift; cursor tips stay clear of the cursor, with 24px of hysteresis before switching back
Keep clear of sticky headers and bottom bars
Every non-modal overlay, tooltips, dropdown menus and toasts above all, should keep clear of containers fixed to the top or bottom (a top navigation bar, a bottom player bar, a tab bar, a chat input): when working out the room, subtract the height these fixed bars take up first. A toast should sit above the bottom bar so it doesn’t cover the playback controls or the main navigation; an overlay that doesn’t close on scroll should hide as soon as its trigger scrolls under the sticky header, rather than hang over the navigation bar. A modal dialog takes over the whole screen with its backdrop, so it may cover the top and bottom bars, and its room is the whole viewport.
- Use it for: tooltips and dropdown menus near a sticky header or bottom bar, toasts above a bottom player bar, tab bar or input
- Values: the room excludes the top and bottom bars, toasts 16px above the bottom bar, the overlay hides when the sticky header covers its trigger
Hand it off to AI
Copy the prompt below into an AI tool such as Claude Code, Codex, Cursor or WorkBuddy: it first takes stock of the menus, popovers, tooltips, toasts and dialogs your project already has, finds where they get clipped at an edge or covered by a fixed bar, and lists them in a table; once you confirm, it adds flipping, shifting, height caps and avoidance right in the components.
Check the overlay components my product already has (menus and dropdowns, popovers, tooltips, toasts and dialogs), find where each one breaks at the extremes (by an edge of the window, low on a long page, under a sticky header, above a fixed bottom bar, with long content), and fix the cause in the component, so every place that uses it gets the fix. Diagnose first, and change only what I approve. Work inside my code and components, and do not add a dependency without asking. Every value below is a default to start from. 0. Diagnose - List each overlay component, where it is defined (my own, or a library: Floating UI, Radix, MUI, Ant Design), and how it is placed today: preferred side, offset, whether it flips, shifts or caps its height, what it measures against, whether it is rendered in a portal, and when it places itself again. - Find what stays fixed on screen (sticky headers, bottom bars) and any clipping or scrolling container between an overlay and the window. - Find the places where each one fails: the last rows of a long list, the right end of a header, inside a scrolling panel, a dialog with its longest content. Trace each failure to its cause in the component, not to the page it shows up on. 1. The room - Every overlay stays inside the window less 16px on each side. In the page, also less the sticky header and any fixed bottom bar; modal layers cover the bars. Render overlays in a portal. - Place it again on open, on scroll, on resize and when its own size changes, not once only. 2. Menus and dropdowns - 8px from the trigger. When the preferred side has no room, flip to the other side, then shift along it into the room. - When it is still too tall, cap it to the room and let it scroll inside. - When the page scrolls while the pointer is outside the menu, fade it out and close it. - With Floating UI: offset(8), flip, shift and size with padding 16, and autoUpdate. 3. Dialogs - No taller than the window less 16px. The title bar and the button bar stay put; only the content between them scrolls, with a 1px line where it passes under them. - Where the content is often long, suggest a side drawer on desktop and a full-width bottom sheet on phones, and ask me before changing. 4. Tooltips - By an edge, flip to the opposite side or shift along it; the arrow keeps pointing at the trigger. - With an arrow, choose among 8 placements (above, below, left, right and the four corners) by the room on each side. - A tooltip that follows the pointer sits clear of the cursor, moves to its other side by an edge, and comes back only once the pointer is 24px further in. 5. Fixed bars - No overlay, tooltips above all, covers a sticky header or a bottom bar. Toasts sit 16px above the bottom bar. An overlay whose trigger scrolls under the header hides with it. 6. Report and check - Before changing anything, give me one table, one row per component: | Component | Used in | Today | Cases that fail | Cause | Fix | Values |. Ask me which rows to change. - Afterwards, go back to every failing case and check that it opens whole, inside the room.


























