Skip to main content

Basic and placement

A tooltip is a short label for a control, shown on hover and on keyboard focus. It is role="tooltip" and the control points to it with aria-describedby. The host (group/tip) shows the tooltip with group-hover and group-focus-within, so it needs no script to open. Four placements: top, bottom, left and right. The space between the control and the tooltip belongs to the tooltip (padding), so the pointer can move onto it without it closing.

Icon buttons and badges

Replaces the browser title attribute, which keyboard and touch users never see. An icon button has no text, so its name is the aria-label; the tooltip repeats it for sighted people and is aria-hidden so a screen reader does not say it twice. A badge that explains itself gets tabindex="0" so the keyboard can reach it, and aria-describedby.

Draft Soon

Longer content and variants

A short label stays on one line; for more, use w-max max-w-56 and let it wrap. Keep it to a sentence. Dominant is the default; the solid variants (700 shade in light mode, 200 in dark mode) all keep 4.5:1 for the text. Use a colour only when it means something, such as danger for a warning about a risky action.

Keyboard and touch

Keyboard: Tab to the control and the tooltip shows; Esc hides it. Pointer: it shows on hover and stays while the pointer is over it. Touch: there is no hover, so a tap acts as one and the tooltip shows until the person taps somewhere else. Because of that, never put something the person must read, or a link or a button, in a tooltip: use a popover, or write the text on the page.

Hover, focus or tap me

Options reference

Use the tooltip component with the trigger in its default slot. Only the Esc behaviour needs a small script.

Part Value Description
data-tooltip-host on the host The component wrapper is group/tip relative inline-flex. The Esc script finds it to hide the tooltip.
Tooltip role="tooltip" The bubble. Set id and point the control at it with aria-describedby. Add decorative when the text only repeats an aria-label; the bubble then gets aria-hidden="true".
Show group-hover/tip, group-focus-within/tip Visibility and opacity change; no script opens it. Animation stops with motion-reduce:transition-none.
Place top, bottom, left, right Set placement: top (default), bottom, left or right. The wrapper has padding on the side of the control so there is no gap.
Width whitespace-nowrap or w-max max-w-56 One line by default. Add wrap for longer text.
Variant dominant, primary, success, info, warning, danger Set variant. Background and arrow colour, light and dark pairs.
Esc script tooltip.js Sets data-dismissed on the host while Esc is pressed and clears it when the pointer or focus leaves. It is registered once in main.js.
Focus tabindex="0" Needed on a badge or a text that is not already focusable.