Tooltip
A hint that tells users what a control does when they hover over it or focus it.
A tooltip shows a short hint next to its trigger, so users learn what a control does without leaving their task. It opens when users rest the mouse pointer on the trigger for 600 milliseconds, and at once when they move focus to the trigger with the keyboard. It stays open while the pointer is on the trigger or on the content, and it closes when the pointer or the focus leaves, when users press the trigger or outside of the tooltip, or when they press Escape. Touch input doesn't open the tooltip, so the hint must not hold anything that users need to finish their task. A TooltipProvider around several tooltips sets their delays in one place and opens the next tooltip at once while one of them is open or has just closed. The trigger is a button without styles of its own, so the examples render it as a Button. The content is at most 20rem wide and points to the trigger with an arrow.
Usage
Examples
Top Side
Most controls have room above them, and a hint placed there leaves the content that follows in view. The tooltip opens on this side by default, and side set to "top" makes that choice explicit.
Right Side
Along a navigation at the left edge of the screen, a hint above an item would cover the item before it. With side set to "right", the hint opens beside the item and leaves the rest of the navigation readable.
Bottom Side
Controls in a page header sit close to the top edge of the screen, with little room above them. Set to "bottom", side opens the hint below the control, where the page offers the room it needs.
Left Side
Actions at the end of a table row sit near the right edge of the screen, and a hint above or below them would cover the neighboring rows. Through side set to "left", the hint opens at the height of its row and keeps the rows around it readable.
Keep Open on Click
A control that users press several times in a row, such as one that raises an order quantity step by step, still needs its hint after the first press. Usually a press on the trigger closes the tooltip, while closeOnClick set to false on the trigger keeps it open, so users can read the hint as they continue.
Cursor Tracking on X Axis
On a wide trigger, such as a bar that spans the deliveries of a whole week, a hint at its center can appear far from the pointer. Once trackCursorAxis is set to "x", the hint follows the pointer from side to side and stays where users are looking. When keyboard focus opens it, the hint remains at the trigger.
Provider
In a toolbar, users often move from one control to the next to find the one they need. A TooltipProvider around those tooltips sets their delays in one place, and while one hint is open, the next one appears without delay as the pointer moves on. Unless the provider sets a delay, even the first hint opens as soon as the pointer reaches its trigger.
Controlled
Pointing users to a control they have not used yet, for example after an update, calls for a hint that the application opens on its own. Through open and onOpenChange, the application holds the state of the tooltip, while hover, focus and Escape still work as users expect.
Disabled
A hint loses its purpose once its control states what it does, for example when a collapsed navigation expands and shows its labels. With disabled set on the tooltip, the hint no longer opens and an open one closes, while the control itself stays fully usable.
API Reference
Tooltip
| Prop | open |
|---|---|
| Type | boolean |
| Default | – |
| Description | Sets whether the tooltip is open and makes it controlled. Update it in onOpenChange. |
| Prop | defaultOpen |
|---|---|
| Type | boolean |
| Default | false |
| Description | Opens the tooltip at first render. The tooltip then tracks its open state itself. |
| Prop | onOpenChange |
|---|---|
| Type | (open: boolean, eventDetails: TooltipRootChangeEventDetails) => void |
| Default | – |
| Description | Runs when users open or close the tooltip. It receives the open state that follows. |
| Prop | onOpenChangeComplete |
|---|---|
| Type | (open: boolean) => void |
| Default | – |
| Description | Runs after the tooltip has opened or closed and its animations have finished. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents the tooltip from opening and closes it when it is open. |
| Prop | disableHoverablePopup |
|---|---|
| Type | boolean |
| Default | false |
| Description | Closes the tooltip as soon as the pointer leaves the trigger. Without it, the tooltip stays open while users move the pointer from the trigger onto the content. |
| Prop | trackCursorAxis |
|---|---|
| Type | "none" | "x" | "y" | "both" |
| Default | "none" |
| Description | Sets the axis on which the content follows the mouse pointer: "x" for the horizontal axis, "y" for the vertical axis and "both" for both. With "both", users can't move the pointer onto the content. A tooltip that focus opened stays at the trigger. |
| Prop | triggerId |
|---|---|
| Type | string | null |
| Default | – |
| Description | Sets the ID of the trigger that a controlled tooltip is associated with. A tooltip without open doesn't need it. |
| Prop | defaultTriggerId |
|---|---|
| Type | string | null |
| Default | – |
| Description | Sets the ID of the trigger that the tooltip is associated with when defaultOpen opens it at first render. |
| Prop | handle |
|---|---|
| Type | TooltipHandle<unknown> |
| Default | – |
| Description | Connects the tooltip with triggers that are rendered outside of it. Create the handle with Tooltip.createHandle() from @base-ui/react/tooltip. |
| Prop | actionsRef |
|---|---|
| Type | RefObject<TooltipRootActions | null> |
| Default | – |
| Description | Receives the functions close and unmount. close closes the tooltip from code, and unmount removes its content from the DOM. |
| Prop | children |
|---|---|
| Type | ReactNode | ((arg: { payload: unknown }) => ReactNode) |
| Default | – |
| Description | Holds the parts of the tooltip. A function receives the payload of the trigger that opened the tooltip. |
TooltipTrigger
| Prop | delay |
|---|---|
| Type | number |
| Default | 600 |
| Description | Sets how many milliseconds the pointer must rest on the trigger before the tooltip opens. Inside a TooltipProvider, the delay of the provider replaces the default. Focus opens the tooltip without a delay. |
| Prop | closeDelay |
|---|---|
| Type | number |
| Default | 0 |
| Description | Sets how many milliseconds the tooltip stays open after the pointer has left the trigger and the content. Inside a TooltipProvider, the closeDelay of the provider replaces the default. |
| Prop | closeOnClick |
|---|---|
| Type | boolean |
| Default | true |
| Description | Closes the tooltip when users press the trigger, and keeps it closed when they press before the delay has passed. With false, the tooltip opens and stays open regardless of the press. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from opening the tooltip with this trigger. It doesn't disable the trigger element itself. |
| Prop | handle |
|---|---|
| Type | TooltipHandle<unknown> |
| Default | – |
| Description | Connects the trigger with a tooltip that it is rendered outside of. Pass the same handle to Tooltip. |
| Prop | payload |
|---|---|
| Type | unknown |
| Default | – |
| Description | Passes a value to the tooltip when this trigger opens it. A function as children of Tooltip receives it. |
| Prop | id |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the ID of the trigger element. triggerId and defaultTriggerId of Tooltip refer to it. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the trigger with another component. |
TooltipContent
| Prop | side |
|---|---|
| Type | "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start" |
| Default | "top" |
| Description | Sets the side of the trigger that the content opens on. "inline-start" and "inline-end" follow the reading direction. The content moves to the opposite side when the chosen one has too little space, and to a side on the other axis when neither of the two has enough. |
| Prop | sideOffset |
|---|---|
| Type | number | OffsetFunction |
| Default | 4 |
| Description | Sets the distance between the trigger and the content in pixels. A function receives the side, the alignment and the dimensions of the trigger and the content, and returns the distance. |
| Prop | align |
|---|---|
| Type | "start" | "center" | "end" |
| Default | "center" |
| Description | Sets where the content lines up with the trigger along the chosen side: at its start, its center or its end. |
| Prop | alignOffset |
|---|---|
| Type | number | OffsetFunction |
| Default | 0 |
| Description | Moves the content along the alignment axis by a number of pixels. A function receives the same data as the one for sideOffset and returns the offset. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the content with another component. |
TooltipProvider
| Prop | delay |
|---|---|
| Type | number |
| Default | 0 |
| Description | Sets how many milliseconds the pointer must rest on a trigger before its tooltip opens. It applies to every tooltip in the provider whose trigger sets no delay of its own. While a tooltip in the provider is open, the next one opens at once. |
| Prop | closeDelay |
|---|---|
| Type | number |
| Default | – |
| Description | Sets how many milliseconds a tooltip stays open after the pointer has left its trigger and its content. It applies to every tooltip in the provider whose trigger sets no closeDelay of its own. |
| Prop | timeout |
|---|---|
| Type | number |
| Default | 400 |
| Description | Sets how many milliseconds after a tooltip has closed the next tooltip in the provider still opens at once. |
| Prop | children |
|---|---|
| Type | ReactNode |
| Default | – |
| Description | Holds the tooltips that share the delays. |