Skip to contents

Tooltip

A popup that appears when an element is hovered or focused, showing a hint for sighted users.

Usage guidelines

  • Prefer using tooltips as visual labels only: Tooltips should act as supplementary visual labels for sighted mouse and keyboard users. Tooltips alone are not accessible to touch or screen reader users. See Alternatives to tooltips for more details.
  • Provide an accessible name for the trigger: Tooltips are visual-only elements and are not a replacement for labeling the trigger. The tooltip's trigger must have an aria-label attribute that closely matches the tooltip's content to ensure consistency for screen reader users.

Anatomy

Import the component and assemble its parts:

Anatomy

Alternatives to tooltips

Tooltips should be supplementary popups that provide non-essential clarity in high-density UIs. A user should not miss critical information if they never see a tooltip.

Tooltips don't work well with touch input. Unlike mouse pointers with hover capability, there's no easily discoverable way to reveal a tooltip before tapping its trigger on a touch device.

iOS doesn't provide a system-standard, touch-friendly tooltip affordance, while Android may show a tooltip on long press. However, on the web, long press is often used to trigger contextual menus in the browser, which can lead to potential conflicts. For this reason, tooltips are disabled on touch devices.

Infotips

Popups that open when hovering an info icon should use Popover with the openOnHover prop on the trigger instead of a tooltip. This way, touch users and screen reader users can access the content.

To know when to reach for a popover instead of a tooltip, consider the purpose of the trigger element: If the trigger's purpose is to open the popup itself, it's a popover. If the trigger's purpose is unrelated to opening the popup, it's a tooltip.

Description text

Tooltips are designed for sighted users and are not a reliable way to deliver important information to touch users or assistive technologies. If the description is important to understanding the element, don't hide it behind a tooltip — use inline text or Popover if space is limited, so the information is accessible to everyone.

Since tooltips serve sighted mouse and keyboard users, iconography should clearly communicate the purpose of icon-only triggers, especially on mobile where the text label may not be visible.

If the description is not critical, a tooltip can still be used to provide extra clarity for sighted mouse or keyboard users.

Contextual feedback messages

Use the Toast component's anchoring ability for more ergonomic DX, to ensure the message is announced to screen readers, and to support complex content.

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.

The imperative methods on the handle, such as open() and close(), require a <Tooltip.Root> using the same handle to be mounted. Calls made while no root is attached to the handle — before one mounts, or after it unmounts — are ignored. Each time a root mounts, it starts from fresh state: a call made while no root was attached is not replayed, and no open state carries over from a previous mount.

Detached triggers

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>.

Multiple triggers within the Root part
Multiple detached triggers

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 children snippet of <Tooltip.Root>, which receives the payload.

The payload can be strongly typed by providing a type argument to the createHandle() function:

Detached triggers with payload

Controlled mode with multiple triggers

You can control the tooltip's open state externally by binding the open prop 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 by binding the triggerId prop on <Tooltip.Root> and setting the id prop on each <Tooltip.Trigger>.

Note that there is no separate onTriggerIdChange prop. bind:triggerId follows the trigger that opens or closes the tooltip. The onOpenChange callback also 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 that indicates the new trigger's position relative to the previous one. The value is a space-separated set of up to two tokens (one per axis) — left or right for the horizontal axis and up or down for the vertical axis (for example, right down). Match a single token with the ~= attribute selector, such as [data-activation-direction~='right'].

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.

API reference

Provider

Shares a delay between tooltips. Once one tooltip is visible, its neighbours open instantly. Does not render its own HTML element.

delay number —
Name
Description

How long to wait before opening a tooltip on hover, in milliseconds.

Type
number
closeDelay number —
Description

How long to wait before closing a tooltip, in milliseconds.

Type
number
timeout number 400
Name
Description

Another tooltip opens instantly if the previous one closed within this time, in milliseconds.

Type
number
Default
400

Root

Groups all parts of the tooltip. Does not render its own HTML element.

open boolean false
Name
Description

Whether the tooltip is open. Use bind:open to share it with the parent. A value passed without bind: holds until the parent changes it.

Type
boolean
Default
false
Binding
bind:open
onOpenChange function —
Description

Called before the open state changes. Call eventDetails.cancel() to veto it.

Type
(open: boolean, details: TooltipChangeEventDetails) => void
onOpenChangeComplete function —
Description

Called after the open or close transition finishes.

Type
(open: boolean) => void
disableHoverablePopup boolean false
Description

Whether the tooltip contents can be hovered without closing the tooltip.

Type
boolean
Default
false
trackCursorAxis TrackCursorAxis 'none'
Description

Which axis the tooltip follows the cursor on.

Type
TrackCursorAxis
Default
'none'
disabled boolean false
Description

Whether the tooltip is disabled.

Type
boolean
Default
false
triggerId string | null —
Description

Id of the trigger the tooltip belongs to. Use bind:triggerId to follow it. An id written by a trigger press resets to null once the popup unmounts.

Type
string | null
Binding
bind:triggerId
handle TooltipHandle<Payload> —
Name
Description

Associates detached triggers and imperative open and close.

Type
TooltipHandle<Payload>
children Snippet<[{ payload: Payload | undefined }]> —
Type
Snippet<[{ payload: Payload | undefined }]>

Trigger

An element to attach the tooltip to. Renders a <button> element.

handle TooltipHandle<Payload> —
Name
Type
TooltipHandle<Payload>
payload Payload —
Name
Description

A payload passed to the tooltip when this trigger opens it.

Type
Payload
id string | null —
Name
Type
string | null
delay number 600
Name
Description

How long to wait before opening the tooltip on hover, in milliseconds.

Type
number
Default
600
closeOnClick boolean true
Description

Whether the tooltip closes when this trigger is clicked.

Type
boolean
Default
true
closeDelay number 0
Description

How long to wait before closing the tooltip, in milliseconds.

Type
number
Default
0
disabled boolean | null —
Description

Whether this trigger does not open the tooltip. It does not set the disabled attribute on the element. Defaults to the root's disabled.

Type
boolean | null
render Snippet<[props: TooltipTriggerHostProps, state: TooltipTriggerState, children: Snippet | undefined]> —
Name
Type
Snippet<[props: TooltipTriggerHostProps, state: TooltipTriggerState, children: Snippet | undefined]>
open boolean
Name
open
Description

Whether the tooltip is open and was opened by this trigger.

Type
boolean
data-popup-open
Present when the corresponding tooltip is open.
data-trigger-disabled
Present when the trigger is disabled, either by the disabled prop or by a parent <Tooltip.Root> component.

Portal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>.

keepMounted boolean false
Description

Keep the portal mounted while the popup is closed.

Type
boolean
Default
false
container HTMLElement | ShadowRoot | null —
Description

Element the portal is appended to. undefined uses the parent portal or document.body. null waits and does not mount until an element or shadow root is set. There is no ref object.

Type
HTMLElement | ShadowRoot | null
render Snippet<[props: HTMLAttributes<HTMLDivElement> & Record<symbol, Attachment<HTMLDivElement>>, state: TooltipPortalState, children: Snippet | undefined]> —
Name
Description

Replace the portal element. The snippet receives host props, an empty state, and the children snippet. Host props include the move attachment.

Type
Snippet<[props: HTMLAttributes<HTMLDivElement> & Record<symbol, Attachment<HTMLDivElement>>, state: TooltipPortalState, children: Snippet | undefined]>

Positioner

Positions the tooltip against the trigger. Renders a <div> element.

anchor Anchor —
Name
Description

An element to position the popup against. Defaults to the trigger.

Type
Anchor
positionMethod "absolute" | "fixed" 'absolute'
Type
"absolute" | "fixed"
Default
'absolute'
side Side 'top'
Name
Description

Which side of the anchor to place the popup on. May change to avoid collisions.

Type
Side
Default
'top'
align Align 'center'
Name
Type
Align
Default
'center'
sideOffset number | OffsetFunction 0
Type
number | OffsetFunction
Default
0
alignOffset number | OffsetFunction 0
Type
number | OffsetFunction
Default
0
collisionBoundary Boundary 'clipping-ancestors'
Type
Boundary
Default
'clipping-ancestors'
collisionPadding Padding 5
Type
Padding
Default
5
arrowPadding number 5
Type
number
Default
5
sticky boolean false
Name
Type
boolean
Default
false
disableAnchorTracking boolean false
Type
boolean
Default
false
collisionAvoidance CollisionAvoidance —
Type
CollisionAvoidance
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipPositionerState, children: Snippet | undefined]> —
Name
Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipPositionerState, children: Snippet | undefined]>
open boolean
Name
open
Type
boolean
side Side
Name
side
Type
Side
align Align
Name
align
Type
Align
anchorHidden boolean
Name
anchorHidden
Type
boolean
instant TooltipInstant | 'tracking-cursor' | undefined
Name
instant
Description

'tracking-cursor' while the tooltip follows the cursor.

Type
TooltipInstant | 'tracking-cursor' | undefined
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.
--positioner-height
The height of the tooltip's positioner. It is important to set height to this value when using CSS to animate size changes.
--positioner-width
The width of the tooltip's positioner. It is important to set width to this value when using CSS to animate size changes.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.

A container for the tooltip contents. Renders a <div> element.

render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipPopupState, children: Snippet | undefined]> —
Name
Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipPopupState, children: Snippet | undefined]>
open boolean
Name
open
Type
boolean
side Side
Name
side
Type
Side
align Align
Name
align
Type
Align
instant TooltipInstant | undefined
Name
instant
Type
TooltipInstant | undefined
transitionStatus 'starting' | 'ending' | 'idle' | undefined
Name
transitionStatus
Type
'starting' | 'ending' | 'idle' | undefined
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 begins 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.

render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipArrowState, children: Snippet | undefined]> —
Name
Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipArrowState, children: Snippet | undefined]>
open boolean
Name
open
Type
boolean
side Side
Name
side
Type
Side
align Align
Name
align
Type
Align
uncentered boolean
Name
uncentered
Type
boolean
instant TooltipInstant | undefined
Name
instant
Type
TooltipInstant | undefined
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-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.

Viewport

A viewport for displaying content transitions. Renders a <div> element. Only needed when one tooltip has several triggers, its content follows the trigger, and switching between them is animated.

render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipViewportState, children: Snippet | undefined]> —
Name
Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: TooltipViewportState, children: Snippet | undefined]>
activationDirection string | undefined
Name
activationDirection
Description

The direction from the previous trigger to the new one, as a horizontal and a vertical value separated by a space. Either value is empty when that axis did not move.

Type
string | undefined
transitioning boolean
Name
transitioning
Type
boolean
instant TooltipInstant | undefined
Name
instant
Type
TooltipInstant | undefined

The Viewport is optional — reach for it only when a single popup is opened by multiple triggers, its content differs per trigger, and the switch between them is animated. When used, set width: var(--positioner-width) and height: var(--positioner-height) on the Positioner so its box is frozen to the measured size during the transition; otherwise content-driven resizing can make the popup thrash or flip to another side.

data-activation-direction
Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.
data-current
Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.
data-instant
Present if animations should be instant.
data-previous
Applied to the direct child of the viewport that contains the exiting content when transitions are present.
data-transitioning
Indicates that the viewport is currently transitioning between old and new content.
--popup-height
The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.
--popup-width
The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

createHandle

Creates a new handle to connect a Tooltip.Root with detached Tooltip.Trigger components.

Handle

Controls a Tooltip imperatively and associates detached Tooltip.Trigger components with a Tooltip.Root. Create one with Tooltip.createHandle() and pass it to the handle prop of the root and of any triggers rendered outside of it.

The imperative methods take effect only while a root using this handle is mounted; calls made before a root attaches (or after it unmounts) are ignored.

PropertyTypeModifiersDescription
isOpenbooleanreadonlyWhether the tooltip is currently open. Returns false while no root is attached to the handle.
payloadPayload \| undefinedreadonlyThe payload of the trigger that opened the tooltip.

Opens the tooltip and associates it with the trigger with the given id. It throws when no trigger with that id is registered, because the tooltip needs a trigger to anchor to.

This method should only be called in an event handler or an effect (not during rendering).

Closes the tooltip.

This method should only be called in an event handler or an effect (not during rendering).

Ends the closing phase of the tooltip immediately.