Tooltip
A short text hint for the element it wraps, shown on hover and on keyboard focus. Inverse surface, the opposite of the current mode (light in dark mode, dark in light mode), with a medium shadow and 14px text. Text only: anything a user acts on belongs in a popover or a dialog.
Preview
Usage
When to use
- Name what an icon button does for sighted users, in the same words as its aria-label.
- Show a detail some users want but nobody needs, such as the full date behind 2 hours ago.
When not to use
- Anything a user must read to finish a task. Write it on the page, or in the description of a Field.
- Links, buttons or other controls inside the hint. Use Dialog for anything the user acts on.
- The only name of an icon button. Give the button aria-label as well.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| content | Yes | Yes | Yes | |
| side | Yes | Yes | Yes | |
| align | Yes | Yes | Yes | |
| sideOffset | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| delayDuration | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| disabled | Yes | Yes | Yes | |
| open | Yes | Yes | Yes | |
| defaultOpen | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| onOpenChange | Yes | Yes | Yes | |
| value of keyboard: Tab | Yes | Deferred | Deferred | |
| value of keyboard: Escape | Yes | Deferred | Deferred |
Variants
side
Side of the trigger the tooltip opens on. It flips when there is no room.
align
Alignment along the trigger's edge.
Examples
Default
Extra detail
A full date behind a relative one, for the few users who want it.
Do and don't
Do
- Name what an icon button does, in the same words as its aria-label.
- Add a fact the user may want but doesn't need: a full date behind a relative one, a shortcut.
- Keep it to a few words on one line.
- Wrap tooltips that sit together, such as the buttons of a toolbar, in TooltipGroup: once one has shown, the next opens at once, with no delay and no fade.
Don't
- Don't put links, buttons or other controls in a tooltip.
- Don't use a tooltip as the only name of an icon button.
- Don't put anything a user needs to finish a task only in a tooltip.
- Don't wrap an element that can't take focus, such as plain text or a disabled button.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| content required | node | - | - | The hint: a few words of plain text, sentence case, no period for a fragment. Copy link, Archived 3 days ago. |
| side | enum | top | right | bottom | left | top | Side of the trigger the tooltip opens on. It flips when there is no room. |
| align | enum | start | center | end | center | Alignment along the trigger's edge. |
| sideOffset | number | - | 4 | Gap between the trigger and the tooltip in px; 4 matches spacing-xs. Not generated for iOS and Android. |
| delayDuration | number | - | 200 | Wait in ms before a hover opens the tooltip. Focus opens it at once. Inside a TooltipGroup the group's delay applies unless this is set. Not generated for iOS and Android. |
| disabled | boolean | - | false | Renders the trigger without a tooltip. |
| open | boolean | - | - | Controlled open state, for a tour or a test. Pair it with onOpenChange. |
| defaultOpen | boolean | - | - | Open on first render, when you don't control it. Not generated for iOS and Android. |
| onOpenChange | function | - | - | Called with true or false when hover, focus or Escape opens or closes the tooltip. |
Not generated: TooltipGroup.
Slots
| Name | Required | Description |
|---|---|---|
| trigger | yes | One element that takes focus: a Button, a link. The tooltip describes it. |
Anatomy
| Part | Description |
|---|---|
| root | The tooltip: inverse fill (light on a dark page, dark on a light one) with inverse text, a transparent border (it shows in forced-colors mode, which drops the fill), radius-element, shadow-med, 14px text, at most 320px wide. |
| trigger | The child element it describes. Gets aria-describedby while the tooltip is open. |
Accessibility
Role: tooltip
| Keys | Action |
|---|---|
| Tab | Focus on the trigger opens the tooltip at once. |
| Escape | Closes the tooltip; focus stays on the trigger. |
- The trigger must take focus (a button or a link), so keyboard users get the hint too. The tooltip text is read as the trigger's description.
- A tooltip never names an icon button on its own: the button still needs aria-label.
- Hover doesn't exist on touch screens. Don't put anything a user needs only in a tooltip.
- The tooltip stays open while the pointer moves onto it, so it can be read at any zoom.
Install
npx werewolf-ui add tooltipRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.