Tooltip
A Tooltip shows users the name of a control while the pointer or keyboard focus is on it.
When to Use
- to show the name of an icon-only Button, in the words of its
aria-label - to show the shortcut of a control, in a Kbd after its name
- to name the items of a Sidebar that is collapsed to icons, through the
tooltipprop ofSidebarMenuButton
When Not to Use
- for text that users need to finish a task, such as a hint or a format (write it on the page, for example in the
FieldDescriptionof a Field) - for the text behind an info icon (use a Popover with
openOnHover) - for content that contains a link or a Button, as focus never moves into a Tooltip (use a Popover)
- to preview the page behind a link (use a Hover Card)
See Popover for a comparison of the Popover, the Tooltip, and the Hover Card.
Avoid placing text that users need to finish a task in a Tooltip, as a tap doesn’t open a Tooltip and screen readers don’t announce one.
Nine digits, with no spaces.
FieldDescription.Anatomy
| Element | Usage |
|---|---|
| Popup | Required |
| Kbd | Optional |
| Trigger | Required |
TooltipContent renders the portal, the positioner, the popup, and the arrow that points at the trigger.
Behavior
A Tooltip responds to a pointer and to keyboard focus. A tap doesn’t open one.
By default, a Tooltip inside a TooltipProvider appears after the pointer has rested on its trigger for 200ms. If another Tooltip is opened within 400ms of one closing, it appears with no delay and no transition. This allows users to move the pointer along a toolbar and read each name in turn. If there is no TooltipProvider, every Tooltip waits 600ms, which is Base UI’s default. When the trigger receives keyboard focus, its Tooltip opens immediately.
A Tooltip closes when the pointer or focus moves away, when users press Escape, and when users click its trigger.
Position and Size
By default, a Tooltip opens above its trigger, centered on it. If it doesn’t fit there, Base UI moves it to another side. To change the position, set side, sideOffset, align, and alignOffset on TooltipContent.
The popup is as wide as its text, up to 320px, and longer text wraps.
Content
| String | Rule | Example | Counterexample |
|---|---|---|---|
| Name | Use the words of the trigger’s aria-label | “Add client” | “Click to add a new client” |
| Name | Sentence case | “Add client” | “Add Client” |
| Shortcut | Place it in a Kbd after the name | “Print the invoice ⌘P” | “Print the invoice (⌘P)” |
Accessibility
A Tooltip is visual only. Base UI sets no role on the popup, and no attribute connects the popup to the trigger, so screen readers announce the trigger’s own name and never the Tooltip.
Requirements
The trigger of a Tooltip needs its own name so that screen readers can announce it, as WCAG 2.2 SC 4.1.2 Name, Role, Value requires.
The Tooltip itself isn’t announced. On an icon-only Button, set aria-label to the words in the Tooltip.
Installation
npx shadcn@latest add @summit/tooltipUsage
Render one TooltipProvider around the app so that all Tooltips share the 200ms delay.
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { PlusIcon } from '@phosphor-icons/react';
<TooltipProvider>
<Tooltip>
<TooltipTrigger render={<Button variant="outline" size="icon" aria-label="Add client" />}>
<PlusIcon />
</TooltipTrigger>
<TooltipContent>Add client</TooltipContent>
</Tooltip>
</TooltipProvider>;With a Shortcut
To show a shortcut, place a Kbd or a KbdGroup after the text.
import { Kbd, KbdGroup } from '@/components/ui/kbd';
<Tooltip>
<TooltipTrigger render={<Button variant="outline" />}>Print</TooltipTrigger>
<TooltipContent>
Print the invoice
<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>P</Kbd>
</KbdGroup>
</TooltipContent>
</Tooltip>;API Reference
The parts accept the props of their matching parts in Base UI’s Tooltip, where TooltipContent is Tooltip.Popup. See the Base UI Tooltip documentation for closeDelay, timeout, disabled, and closeOnClick.
TooltipProvider
| Prop | Type | Default | Description |
|---|---|---|---|
delay | number | 200 | The delay before the first Tooltip opens, in milliseconds |
TooltipContent
| Prop | Type | Default | Description |
|---|---|---|---|
side | 'top' | 'bottom' | 'left' | 'right' | 'inline-start' | 'inline-end' | 'top' | The side of the trigger the Tooltip opens on |
sideOffset | number | OffsetFunction | 4 | The gap between the trigger and the Tooltip, in pixels |
align | 'start' | 'center' | 'end' | 'center' | The edge of the trigger the Tooltip lines up with |
alignOffset | number | OffsetFunction | 0 | A shift along that edge, in pixels |