Skip to content

Tooltip

.bp-tooltip is a CSS-only tooltip triggered by hover and :focus-within on a .bp-tooltip-wrap container. It supports four placements (top default, bottom, start, end) and is RTL-aware via CSS logical properties. No JavaScript required.

npm

@import "@be-partner-labs/ds/components/tooltip";

CDN

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@be-partner-labs/ds/dist/components/tooltip.min.css">

For the full bundle: https://cdn.jsdelivr.net/npm/@be-partner-labs/ds/dist/bpl-ds.min.css

Top (default)

Helpful context
<span class="bp-tooltip-wrap">
<button class="bp-btn bp-btn--outline">Hover me</button>
<span class="bp-tooltip" role="tooltip">Helpful context</span>
</span>

All placements

Tooltip on top Tooltip on bottom Tooltip on start Tooltip on end
<div class="demo-tooltip-grid">
<span class="bp-tooltip-wrap">
<button class="bp-btn bp-btn--outline">Top</button>
<span class="bp-tooltip" role="tooltip">Tooltip on top</span>
</span>
<span class="bp-tooltip-wrap">
<button class="bp-btn bp-btn--outline">Bottom</button>
<span class="bp-tooltip bp-tooltip--bottom" role="tooltip">Tooltip on bottom</span>
</span>
<span class="bp-tooltip-wrap">
<button class="bp-btn bp-btn--outline">Start</button>
<span class="bp-tooltip bp-tooltip--start" role="tooltip">Tooltip on start</span>
</span>
<span class="bp-tooltip-wrap">
<button class="bp-btn bp-btn--outline">End</button>
<span class="bp-tooltip bp-tooltip--end" role="tooltip">Tooltip on end</span>
</span>
</div>
Variable Default Description
--tooltip-background --bp-color-text Background color
--tooltip-color --bp-color-bg Text color
--tooltip-border-radius --bp-radius-md Border radius · Alias --tooltip-radius deprecated, removed in v2
--tooltip-size --bp-text-xs Font size
--tooltip-padding --bp-space-1 --bp-space-2 Padding
--tooltip-delay 0.3s Show delay — long enough to survive an accidental cursor graze
--tooltip-offset 0.5rem Distance from trigger
--tooltip-max-width 300px Max bubble width — text wraps instead of running on; if it needs more, it’s not a tooltip

Custom color

This action cannot be undone
<span class="bp-tooltip-wrap">
<button class="bp-btn bp-btn--primary">Info</button>
<span class="bp-tooltip demo-tooltip--info" role="tooltip">
This action cannot be undone
</span>
</span>

Anchor Positioning (progressive enhancement)

Section titled “Anchor Positioning (progressive enhancement)”

By default the tooltip uses position: absolute inside .bp-tooltip-wrap. This works everywhere but gets clipped by overflow: hidden parents.

To opt into CSS Anchor Positioning — which renders the tooltip in the browser’s top layer, above everything — set --tooltip-anchor to a unique dashed-ident on the wrapper:

Anchor Positioning (Chrome/Edge)

Ctrl+S
<span class="bp-tooltip-wrap" style="--tooltip-anchor: --tip-save">
<button class="bp-btn bp-btn--primary">Save</button>
<span class="bp-tooltip" role="tooltip">Ctrl+S</span>
</span>

When anchor-name is supported, the CSS automatically uses it and adds position-try-fallbacks — if the tooltip would overflow the viewport (top edge, right edge), the browser tries bottom → end → start automatically. No JS needed. In other browsers, it silently falls back to position: absolute.

Why the naming is manual, not automatic: an anchor-scope-based version that reused one shared anchor-name per .bp-tooltip-wrap (no naming needed at all) was tested and reverted — verified in Chrome 150 that anchor-scope combined with position-try-fallbacks cross-contaminates between sibling tooltip instances once a fallback position engages: a tooltip can render anchored to a different trigger’s position, elsewhere on the page. Each instance needs its own unique --tooltip-anchor until that engine interaction is reliable.

Polyfill: @oddbird/css-anchor-positioning by OddBird (Miriam Suzanne’s team) adds support to Firefox and Safari today:

<script type="module">
if (!("anchorName" in document.documentElement.style)) {
import("https://unpkg.com/@oddbird/css-anchor-positioning");
}
</script>
Class Position
(none) Top center (default)
.bp-tooltip--bottom Below the trigger
.bp-tooltip--start Inline start (left in LTR, right in RTL)
.bp-tooltip--end Inline end (right in LTR, left in RTL)
✓No axe violationstested 2026-05-11
  • Add role="tooltip" to the .bp-tooltip element.
  • Add aria-describedby="<id>" on the trigger pointing to the tooltip’s id for screen readers.
  • The tooltip is shown on :focus-within — keyboard users get it automatically when focusing the trigger.
  • Keep tooltip text short and non-interactive — tooltips are not reachable by mouse from the bubble.
  • For interactive content (links, buttons inside the tip), use a popover instead.
<span class="bp-tooltip-wrap">
<button aria-describedby="tip-save">Save</button>
<span id="tip-save" class="bp-tooltip" role="tooltip">Ctrl+S</span>
</span>
API Availability Used for Without it
:focus-within Widely availableBaseline 2018 Keyboard trigger Tooltip only shows on hover
CSS logical properties Widely availableBaseline 2023 RTL placement Use physical left/right
CSS Anchor Positioning Newly availableBaseline 2025 Top-layer tooltip (opt-in) Falls back to position: absolute
position-try-fallbacks Newly availableBaseline 2025 Auto-flip when near viewport edge No auto-flip
visibility + opacity transition Widely availableBaseline 2012 Smooth show/hide Instant show/hide

The tooltip is position: absolute inside the inline-flex wrapper (upgraded to anchor-positioned position: fixed when supported — see above). Show/hide is done via opacity + visibility transition — visibility: hidden removes it from tab order when not visible, opacity: 0 animates the fade. The 300ms delay is applied via transition-delay so the tooltip doesn’t flash on every accidental cursor graze across the trigger. The arrow is a CSS border trick via ::after. Bubble width is capped at --tooltip-max-width (300px default) with text-wrap: pretty, so long copy wraps instead of running off-screen.