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-labelledbyattribute. 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
openOnHoverprop instead. Tooltips should describe an element that performs an action separate from opening the tooltip itself. - Avoid for transient information: Use the Toast component’s anchoring ability instead of Tooltip for transient notifications, like a “Copied” popup that appears above a copy-to-clipboard button. This way, the message is announced to screen readers when it appears. Toasts can also contain more complex content, such as links or actions.
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.
delaynumber
—
delaynumber
—- Name
- Description
How long to wait before opening a tooltip. Specified in milliseconds.
- Type
number | undefined
closeDelaynumber
—
closeDelaynumber
—- Name
- Description
How long to wait before closing a tooltip. Specified in milliseconds.
- Type
number | undefined
timeoutnumber
400
timeoutnumber
400
- Name
- Description
Another tooltip will open instantly if the previous tooltip is closed within this timeout. Specified in milliseconds.
- Type
number | undefined- Default
400
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
Root
Groups all parts of the tooltip. Doesn’t render its own HTML element.
defaultOpenboolean
false
defaultOpenboolean
false
- Name
- Description
Whether the tooltip is initially open.
To render a controlled tooltip, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean
—
openboolean
—- Name
- Description
Whether the tooltip is currently open.
- Type
boolean | undefined
onOpenChangefunction
—
onOpenChangefunction
—- Name
- Description
Event handler called when the tooltip is opened or closed.
- Type
| (( open: boolean, eventDetails: Tooltip.Root.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<Tooltip.Root.Actions>
—
actionsRefRefObject<Tooltip.Root.Actions>
—- Name
- Description
A ref to imperative actions.
unmount: When specified, the tooltip will not be unmounted when closed. Instead, theunmountfunction must be called to unmount the tooltip manually. Useful when the tooltip's animation is controlled by an external library.
- Type
React.RefObject<Tooltip.Root.Actions> | undefined
defaultTriggerIdstring | null
—
defaultTriggerIdstring | null
—- Name
- Description
ID of the trigger that the tooltip is associated with. This is useful in conjunction with the
defaultOpenprop to create an initially open tooltip.- Type
string | null | undefined
handleTooltipHandle<Payload>
—
handleTooltipHandle<Payload>
—- Name
- Description
A handle to associate the tooltip with a trigger. If specified, allows external triggers to control the tooltip's open state. Can be created with the Tooltip.createHandle() method.
- Type
{} | undefined
onOpenChangeCompletefunction
—
onOpenChangeCompletefunction
—- Description
Event handler called after any animations complete when the tooltip is opened or closed.
- Type
((open: boolean) => void) | undefined
triggerIdstring | null
—
triggerIdstring | null
—- Name
- Description
ID of the trigger that the tooltip is associated with. This is useful in conjuntion with the
openprop to create a controlled tooltip. There's no need to specify this prop when the tooltip is uncontrolled (i.e. when theopenprop is not set).- Type
string | null | undefined
trackCursorAxisUnion
'none'
trackCursorAxisUnion
'none'
- Name
- Description
Determines which axis the tooltip should track the cursor on.
- Type
'none' | 'both' | 'x' | 'y' | undefined- Default
'none'
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the tooltip is disabled.
- Type
boolean | undefined- Default
false
hoverableboolean
true
hoverableboolean
true
- Name
- Description
Whether the tooltip contents can be hovered without closing the tooltip.
- Type
boolean | undefined- Default
true
childrenReactNode | PayloadChildRenderFunction<Payload>
—
childrenReactNode | PayloadChildRenderFunction<Payload>
—- Name
- Description
The content of the tooltip. This can be a regular React node or a render function that receives the
payloadof the active trigger.- Type
| React.ReactNode | ((arg: { payload: Payload | undefined }) => ReactNode)
Trigger
An element to attach the tooltip to.
Renders a <button> element.
handleTooltipHandle<Payload>
—
handleTooltipHandle<Payload>
—- Name
- Description
A handle to associate the trigger with a tooltip.
- Type
{} | undefined
payloadPayload
—
payloadPayload
—- Name
- Description
A payload to pass to the tooltip when it is opened.
- Type
Payload | undefined
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
| React.CSSProperties | (( state: Tooltip.Trigger.State, ) => CSSProperties | undefined) | undefined
delaynumber
600
delaynumber
600
- Name
- Description
How long to wait before opening the tooltip. Specified in milliseconds.
- Type
number | undefined- Default
600
closeDelaynumber
0
closeDelaynumber
0
- Name
- Description
How long to wait before closing the tooltip. Specified in milliseconds.
- Type
number | undefined- Default
0
classNamestring | function
—
classNamestring | 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 | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor 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>.
Renders a <div> element.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
| React.CSSProperties | (( state: Tooltip.Portal.State, ) => CSSProperties | undefined) | undefined
containerUnion
—
containerUnion
—- Name
- Description
A parent element to render the portal element into.
- Type
| HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
classNamestring | function
—
classNamestring | 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.Portal.State) => string | undefined)
keepMountedboolean
false
keepMountedboolean
false
- Name
- Description
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tooltip.Portal.State, ) => ReactElement)
Positioner
Positions the tooltip against the trigger.
Renders a <div> element.
collisionAvoidanceCollisionAvoidance
—
collisionAvoidanceCollisionAvoidance
—- Description
Determines how to handle collisions when positioning the popup.
- Type
| { side?: 'none' | 'flip' align?: 'none' | 'flip' | 'shift' fallbackAxisSide?: 'none' | 'end' | 'start' } | { side?: 'none' | 'shift' align?: 'none' | 'shift' fallbackAxisSide?: 'none' | 'end' | 'start' } | undefined- Example
<Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
| React.CSSProperties | (( state: Tooltip.Positioner.State, ) => CSSProperties | undefined) | undefined
alignAlign
'center'
alignAlign
'center'
- Name
- Description
How to align the popup relative to the specified side.
- Type
'center' | 'end' | 'start' | undefined- Default
'center'
alignOffsetnumber | OffsetFunction
0
alignOffsetnumber | 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.
The function takes a
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.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 | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined- Default
0- Example
<Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide
'top'
sideSide
'top'
- Name
- Description
Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
- Type
| 'left' | 'right' | 'bottom' | 'top' | 'inline-end' | 'inline-start' | undefined- Default
'top'
sideOffsetnumber | OffsetFunction
0
sideOffsetnumber | 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.
The function takes a
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.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 | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined- Default
0- Example
<Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber
5
arrowPaddingnumber
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 | undefined- Default
5
anchorUnion
—
anchorUnion
—- Name
- Description
An element to position the popup against. By default, the popup will be positioned against the trigger.
- Type
| Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | undefined
collisionBoundaryBoundary
'clipping-ancestors'
collisionBoundaryBoundary
'clipping-ancestors'
- Description
An element or a rectangle that delimits the area that the popup is confined to.
- Type
| Element | 'clipping-ancestors' | Element[] | Rect | undefined- Default
'clipping-ancestors'
collisionPaddingPadding
5
collisionPaddingPadding
5
- Name
- Description
Additional space to maintain from the edge of the collision boundary.
- Type
| { top?: number right?: number bottom?: number left?: number } | number | undefined- Default
5
stickyboolean
false
stickyboolean
false
- Name
- Description
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
- Type
boolean | undefined- Default
false
positionMethod'fixed' | 'absolute'
'absolute'
positionMethod'fixed' | 'absolute'
'absolute'
- Name
- Description
Determines which CSS
positionproperty to use.- Type
'fixed' | 'absolute' | undefined- Default
'absolute'
trackAnchorboolean
true
trackAnchorboolean
true
- Name
- Description
Whether the popup tracks any layout shift of its positioning anchor.
- Type
boolean | undefined- Default
true
classNamestring | function
—
classNamestring | 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 | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor 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.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
| React.CSSProperties | (( state: Tooltip.Popup.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | 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 | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor 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.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
| React.CSSProperties | (( state: Tooltip.Arrow.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | 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 | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor 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-instant
Present if animations should be instant.
data-side
Indicates which side the popup is positioned relative to the trigger.
Examples
Detached triggers
A tooltip can be controlled by a trigger located either inside or outside the <Tooltip.Root> component.
For simple, one-off interactions, place the <Tooltip.Trigger> inside <Tooltip.Root>, as shown in the example at the top of this page.
However, if defining the tooltip’s content next to its trigger is not practical, you can use a detached trigger.
This involves placing the <Tooltip.Trigger> outside of <Tooltip.Root> and linking them with a handle created by the Tooltip.createHandle() function.
const demoTooltip = Tooltip.createHandle();
<Tooltip.Trigger handle={demoTooltip}>Button</Tooltip.Trigger>
<Tooltip.Root handle={demoTooltip}>
...
</Tooltip.Root>Multiple triggers
A single tooltip can be opened by multiple trigger elements.
You can achieve this by using the same handle for several detached triggers, or by placing multiple <Tooltip.Trigger> components inside a single <Tooltip.Root>.
<Tooltip.Root>
<Tooltip.Trigger>Trigger 1</Tooltip.Trigger>
<Tooltip.Trigger>Trigger 2</Tooltip.Trigger>
...
</Tooltip.Root>const demoTooltip = Tooltip.createHandle();
<Tooltip.Trigger handle={demoTooltip}>
Trigger 1
</Tooltip.Trigger>
<Tooltip.Trigger handle={demoTooltip}>
Trigger 2
</Tooltip.Trigger>
<Tooltip.Root handle={demoTooltip}>
...
</Tooltip.Root>The tooltip can render different content depending on which trigger opened it.
This is achieved by passing a payload to the <Tooltip.Trigger> and using the function-as-a-child pattern in <Tooltip.Root>.
The payload can be strongly typed by providing a type argument to the createHandle() function:
const demoTooltip = Tooltip.createHandle<{ text: string }>();
<Tooltip.Trigger handle={demoTooltip} payload={{ text: 'Trigger 1' }}>
Trigger 1
</Tooltip.Trigger>
<Tooltip.Trigger handle={demoTooltip} payload={{ text: 'Trigger 2' }}>
Trigger 2
</Tooltip.Trigger>
<Tooltip.Root handle={demoTooltip}>
{({ payload }) => (
<Tooltip.Portal>
<Tooltip.Positioner sideOffset={8}>
<Tooltip.Popup className={styles.Popup}>
<Tooltip.Arrow className={styles.Arrow}>
<ArrowSvg />
</Tooltip.Arrow>
{payload !== undefined && (
<span>
Tooltip opened by {payload.text}
</span>
)}
</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
)}
</Tooltip.Root>Controlled mode with multiple triggers
You can control the tooltip’s open state externally using the open and onOpenChange props on <Tooltip.Root>.
This allows you to manage the tooltip’s visibility based on your application’s state.
When using multiple triggers, you have to manage which trigger is active with the triggerId prop on <Tooltip.Root> and the id prop on each <Tooltip.Trigger>.
Note that there is no separate onTriggerIdChange prop.
Instead, the onOpenChange callback receives an additional argument, eventDetails, which contains the trigger element that initiated the state change.
Animating the Tooltip
You can animate a tooltip as it moves between different trigger elements. This includes animating its position, size, and content.
Position and Size
To animate the tooltip’s position, apply CSS transitions to the left, right, top, and bottom properties of the Positioner part.
To animate its size, transition the width and height of the Popup part.
Content
The tooltip also supports content transitions. This is useful when different triggers display different content within the same tooltip.
To enable content animations, wrap the content in the <Tooltip.Viewport> part.
This part provides features to create direction-aware animations.
It renders a div with a data-activation-direction attribute (left, right, up, or down) that indicates the new trigger’s position relative to the previous one.
Inside the <Tooltip.Viewport>, the content is further wrapped in divs with data attributes to help with styling:
data-current: The currently visible content when no transitions are present or the incoming content.data-previous: The outgoing content during a transition.
You can use these attributes to style the enter and exit animations.