Tooltip
A popup that appears when an element is hovered or focused, showing a hint for sighted users.
View as MarkdownAccessibility guidelines
To ensure that tooltips are accessible and helpful, follow these guidelines:
-
Provide an accessible name for the trigger: The tooltip’s trigger must have a meaningful label. This can be its visible text or an
aria-label
/aria-labelledby
attribute. The label should closely match the tooltip’s content to ensure consistency for screen reader users. -
Avoid tooltips for critical information: Tooltips work well for enhancing UI clarity (like labeling icon buttons) but should not be the sole means of conveying important information. Since tooltips do not appear on touch devices, consider using a Popover for essential content.
-
Avoid tooltips for “infotips”: If your tooltip is attached to an “info icon” button whose only purpose is to show the tooltip, opt for Popover and add the
openOnHover
prop instead. Tooltips should describe an element that performs an action separate from opening the tooltip itself.
Anatomy
Import the component and assemble its parts:
import { Tooltip } from '@base-ui-components/react/tooltip';
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger />
<Tooltip.Portal>
<Tooltip.Positioner>
<Tooltip.Popup>
<Tooltip.Arrow />
</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
API reference
Provider
Provides a shared delay for multiple tooltips. The grouping logic ensures that once a tooltip becomes visible, the adjacent tooltips will be shown instantly.
delay
number
number
- Name
- Description
How long to wait before opening a tooltip. Specified in milliseconds.
- Type
number
closeDelay
number
number
- Name
- Description
How long to wait before closing a tooltip. Specified in milliseconds.
- Type
number
timeout
number
(default: 400
)
number
400
- Name
- Description
Another tooltip will open instantly if the previous tooltip is closed within this timeout. Specified in milliseconds.
- Type
number
- Default
400
children
ReactNode
ReactNode
- Name
- Type
ReactNode
Root
Groups all parts of the tooltip. Doesn’t render its own HTML element.
defaultOpen
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the tooltip is initially open.
To render a controlled tooltip, use the
open
prop instead.- Type
boolean
- Default
false
open
boolean
boolean
- Name
- Description
Whether the tooltip is currently open.
- Type
boolean
onOpenChange
function
function
- Name
- Description
Event handler called when the tooltip is opened or closed.
- Type
((open: boolean, event: Event | undefined, reason: Tooltip.Root.OpenChangeReason | undefined) => void)
actionsRef
RefObject<Tooltip.Root.Actions>
RefObject<Tooltip.Root.Actions>
- Name
- Description
A ref to imperative actions.
unmount
: When specified, the tooltip will not be unmounted when closed. Instead, theunmount
function must be called to unmount the tooltip manually. Useful when the tooltip's animation is controlled by an external library.
- Type
RefObject<Tooltip.Root.Actions>
onOpenChangeComplete
function
function
- Description
Event handler called after any animations complete when the tooltip is opened or closed.
- Type
((open: boolean) => void)
trackCursorAxis
Union
(default: 'none'
)
Union
'none'
- Name
- Description
Determines which axis the tooltip should track the cursor on.
- Type
'none' | 'both' | 'x' | 'y'
- Default
'none'
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the tooltip is disabled.
- Type
boolean
- Default
false
delay
number
(default: 600
)
number
600
- Name
- Description
How long to wait before opening the tooltip. Specified in milliseconds.
- Type
number
- Default
600
closeDelay
number
(default: 0
)
number
0
- Name
- Description
How long to wait before closing the tooltip. Specified in milliseconds.
- Type
number
- Default
0
hoverable
boolean
(default: true
)
boolean
true
- Name
- Description
Whether the tooltip contents can be hovered without closing the tooltip.
- Type
boolean
- Default
true
children
ReactNode
ReactNode
- Name
- Type
ReactNode
Trigger
An element to attach the tooltip to.
Renders a <button>
element.
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Tooltip.Trigger.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Tooltip.Trigger.State) => ReactElement)
data-popup-open
Present when the corresponding tooltip is open.
Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>
.
container
Union
Union
- Name
- Description
A parent element to render the portal element into.
- Type
| HTMLElement
| ShadowRoot
| RefObject<HTMLElement
| ShadowRoot
| null>
| null
children
ReactNode
ReactNode
- Name
- Type
ReactNode
keepMounted
boolean
(default: false
)
boolean
false
- Name
- Description
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Type
boolean
- Default
false
Positioner
Positions the tooltip against the trigger.
Renders a <div>
element.
collisionAvoidance
CollisionAvoidance
CollisionAvoidance
- Description
Determines how to handle collisions when positioning the popup.
- Type
CollisionAvoidance
align
Union
(default: 'center'
)
Union
'center'
- Name
- Description
How to align the popup relative to the specified side.
- Type
'center' | 'start' | 'end'
- Default
'center'
alignOffset
number | OffsetFunction
(default: 0
)
number | OffsetFunction
0
- Name
- Description
Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.
data.anchor
: the dimensions of the anchor element with propertieswidth
andheight
.data.positioner
: the dimensions of the positioner element with propertieswidth
andheight
.data.side
: which side of the anchor element the positioner is aligned against.data.align
: how the positioner is aligned relative to the specified side.
- Type
number | OffsetFunction
- Default
0
side
Side
(default: 'top'
)
Side
'top'
- Name
- Description
Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
- Type
Side
- Default
'top'
sideOffset
number | OffsetFunction
(default: 0
)
number | OffsetFunction
0
- Name
- Description
Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.
data.anchor
: the dimensions of the anchor element with propertieswidth
andheight
.data.positioner
: the dimensions of the positioner element with propertieswidth
andheight
.data.side
: which side of the anchor element the positioner is aligned against.data.align
: how the positioner is aligned relative to the specified side.
- Type
number | OffsetFunction
- Default
0
arrowPadding
number
(default: 5
)
number
5
- Name
- Description
Minimum distance to maintain between the arrow and the edges of the popup.
Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
- Type
number
- Default
5
anchor
Union
Union
- Name
- Description
An element to position the popup against. By default, the popup will be positioned against the trigger.
- Type
| Element
| RefObject<Element
| null>
| VirtualElement
| (() => Element | VirtualElement | null)
| null
collisionBoundary
Boundary
(default: 'clipping-ancestors'
)
Boundary
'clipping-ancestors'
- Description
An element or a rectangle that delimits the area that the popup is confined to.
- Type
Boundary
- Default
'clipping-ancestors'
collisionPadding
Padding
(default: 5
)
Padding
5
- Name
- Description
Additional space to maintain from the edge of the collision boundary.
- Type
Padding
- Default
5
sticky
boolean
(default: false
)
boolean
false
- Name
- Description
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
- Type
boolean
- Default
false
positionMethod
'fixed' | 'absolute'
(default: 'absolute'
)
'fixed' | 'absolute'
'absolute'
- Name
- Description
Determines which CSS
position
property to use.- Type
'fixed' | 'absolute'
- Default
'absolute'
trackAnchor
boolean
(default: true
)
boolean
true
- Name
- Description
Whether the popup tracks any layout shift of its positioning anchor.
- Type
boolean
- Default
true
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Tooltip.Positioner.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Tooltip.Positioner.State) => ReactElement)
data-open
Present when the tooltip is open.
data-closed
Present when the tooltip is closed.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
--anchor-height
The anchor's height.
--anchor-width
The anchor's width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
Popup
A container for the tooltip contents.
Renders a <div>
element.
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Tooltip.Popup.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Tooltip.Popup.State) => ReactElement)
data-open
Present when the tooltip is open.
data-closed
Present when the tooltip is closed.
data-align
Indicates how the popup is aligned relative to specified side.
data-instant
Present if animations should be instant.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the tooltip is animating in.
data-ending-style
Present when the tooltip is animating out.
Arrow
Displays an element positioned against the tooltip anchor.
Renders a <div>
element.
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Tooltip.Arrow.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Tooltip.Arrow.State) => ReactElement)
data-open
Present when the tooltip is open.
data-closed
Present when the tooltip is closed.
data-uncentered
Present when the tooltip arrow is uncentered.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.