Skip to content
IndexRequest a UIAboutContact

Tooltip

A short hint that appears on hover or focus, flips to stay inside the screen.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a tooltip component for buttons placed at different positions of a 380x240 panel (left, centre, right and near the top edge). Tooltips are elements with role="tooltip" and unique ids referenced by aria-describedby on their triggers. Show on hover after a 400ms delay and immediately on keyboard focus; hide on mouseleave, blur or Escape, with a 100ms grace so the pointer can travel onto the tooltip without closing it. Position above the trigger by default with an 8px gap and a small arrow; if there is not enough space above, flip below; clamp horizontally so the tooltip never leaves the panel. Animate opacity and a 4px translate over 140ms ease-out. Implement positioning with getBoundingClientRect, no libraries. Reduced motion: opacity only.

About this pattern

Definition

A small floating label that explains an element. It shows when the pointer rests on the element or when the element receives keyboard focus, and hides on leave, blur or Escape.

Purpose & UX principles

  • Names icon-only controls and gives brief extra context.
  • A tooltip is supplementary: never put essential information or interactive content in it, and do not use it on touch-only flows.
  • Hovering the tooltip itself should keep it open so people with tremors or magnifiers can move onto it.

Interaction states

  • Hidden, shown after a 400ms delay on hover (immediately on focus), hiding on mouseleave, blur or Escape.
  • The trigger references the tooltip with aria-describedby, and the tooltip has role="tooltip".

Motion specification

  • Fade and 4px slide towards the trigger, 140ms ease-out.
  • Opening delay 400ms for hover only; closing is instant after a 100ms grace period.
  • Reduced motion: opacity only.

Responsive behaviour

  • If there is no room above, the tooltip flips below. Near the left or right edge it shifts to stay inside the viewport.
  • No hover on touch: use long-press or an explicit help button instead.

Code

HTML
<div class="panel" id="panel">
  <button class="t tl" data-tip="Left edge — clamped inside">Left</button>
  <button class="t tc" data-tip="Centred above the button">Centre</button>
  <button class="t tr" data-tip="Right edge — clamped inside">Right</button>
  <button class="t tt" data-tip="No room above, so I flip below">Top</button>
</div>

Related patterns

Icon Button

↗
Icon ButtonButtons & Actions

Dropdown Menu

↗
Dropdown MenuOverlays & Dialogs

Toast

↗
ToastFeedback & Notifications