Tooltip
The Tooltip component displays contextual information when users hover over or focus on an element. It’s useful for providing additional context without cluttering the interface.Import
Anatomy
The Tooltip component consists of several parts:<Tooltip.Root>- Groups all parts of the tooltip<Tooltip.Trigger>- The element that triggers the tooltip<Tooltip.Positioner>- Positions the tooltip relative to the trigger<Tooltip.Popup>- The tooltip content container<Tooltip.Arrow>- An optional arrow pointing to the trigger<Tooltip.Provider>- Manages shared behavior for multiple tooltips
Basic Usage
Key Features
- Multiple triggers: Hover, focus, and custom triggers
- Smart positioning: Automatically positions to stay in viewport
- Accessible: Proper ARIA attributes and keyboard support
- Delay control: Customize open and close delays
- Cursor tracking: Optionally follow the cursor
- Hoverable content: Keep tooltip open when hovering the popup
- Portal support: Render tooltip in a different DOM location
- Animation support: Built-in transition states
Component Props
Root
Groups all parts of the tooltip and manages open state. Props:open(boolean): Controlled open statedefaultOpen(boolean): Initially open state (default: false)onOpenChange(function): Callback when open state changesonOpenChangeComplete(function): Callback after animations completedisabled(boolean): Whether the tooltip is disabled (default: false)disableHoverablePopup(boolean): Prevent hovering the popup (default: false)trackCursorAxis(string): Track cursor on ‘x’, ‘y’, ‘both’, or ‘none’ (default: ‘none’)actionsRef(ref): Access to imperative actions (unmount, close)handle(TooltipHandle): Associate with external triggerstriggerId(string): ID of the active trigger (controlled mode)defaultTriggerId(string): Initial trigger ID- Doesn’t render its own HTML element
Trigger
The element that triggers the tooltip. Props:delay(number): Open delay in milliseconds (default: 600)closeDelay(number): Close delay in milliseconds (default: 0)closeOnClick(boolean): Whether clicking closes the tooltip (default: true)disabled(boolean): Disable this specific trigger (default: false)handle(TooltipHandle): Associate with a tooltip handlepayload(any): Data to pass to the tooltip- Renders a
<button>element
Positioner
Positions the tooltip relative to the trigger. Props:side(string): Preferred side (‘top’, ‘right’, ‘bottom’, ‘left’)align(string): Alignment (‘start’, ‘center’, ‘end’)sideOffset(number): Distance from the triggeralignOffset(number): Offset along the alignment axiscollisionBoundary(element): Boundary for collision detectionsticky(boolean): Whether to stick to the trigger when scrolling- Renders a
<div>element
Popup
The container for tooltip content. Props:- Renders a
<div>element - Accepts all standard HTML div attributes
open: Whether the tooltip is openside: The current side of placementalign: The current alignmentinstant: The animation instant typetransitionStatus: Current transition state
Arrow
An optional arrow pointing to the trigger. Props:- Renders an
<svg>element - Automatically positioned and rotated
Provider
Manages shared behavior for multiple tooltips. Props:delay(number): Default delay for all tooltipscloseDelay(number): Default close delay for all tooltips
Styling
- Tab Title
- Tab Title