demo · v143

Overflow-Aware Tooltip

Tooltips anchored with anchor-name, position-anchor, and @position-try fallback blocks. Chrome 143 adds @container anchored(...), so the badge inside each tooltip can be styled by the fallback that actually won.

Your browser does not fully support CSS Anchor Positioning or @position-try yet. The demo still renders, but tooltips may not reflow on overflow. Chrome 125+ is required for full support.
Checking anchored container query support…
Fallback highlight

Click any button to show/hide its tooltip. Use the sliders above to resize the container and watch fallbacks activate.

How the CSS is structured

/* 1. Name the anchor element */
.trigger {
  anchor-name: --my-trigger;
}

/* 2. Position the tooltip relative to its anchor */
.tooltip {
  position: absolute;
  position-anchor: --my-trigger;
  container-type: anchored;

  /* preferred position: above */
  bottom: anchor(top);
  left: anchor(left);

  /* fallback list — tried in order */
  position-try-options: --below, --right, --left;
  position-try-order: most-block-size;
}

/* 3. Define each fallback */
@position-try --below {
  top: anchor(bottom);
  left: anchor(left);
}
@position-try --right {
  top: anchor(top);
  left: anchor(right);
}
@position-try --left {
  top: anchor(top);
  right: anchor(left);
}

/* 4. Style the tooltip's own descendants by the chosen fallback */
@container anchored(--below) {
  .fallback-badge::before { content: "--below"; }
}
@container anchored(--right) {
  .fallback-badge::before { content: "--right"; }
}
@container anchored(--left) {
  .fallback-badge::before { content: "--left"; }
}

Key properties

See also