shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A tooltip is a short label that appears beside a control on hover or keyboard focus and goes away when the pointer or focus moves on. Reach for it when a control doesn't say what it does, such as an icon-only button in a toolbar, or to show the keyboard shortcut behind it.
When people need to move into the content or read more than a line, use a Hover Card. Anything they have to click belongs in a Popover.
Installation
Anatomy

Usage
import { Button } from "@/components/ui/button";
import {
Tooltip, TooltipContent, TooltipTrigger,
} from "@/components/ui/tooltip";<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline">Hover</Button>
</TooltipTrigger>
<TooltipContent>
<p>Add to library</p>
</TooltipContent>
</Tooltip>Accessibility
The tooltip has role="tooltip", and while it's open the trigger's aria-describedby points at it, so a screen reader reads its text after the trigger's own name. Keyboard focus opens it at once and Escape closes it. The tooltip only describes the trigger, so an icon-only button still needs a name of its own, such as an aria-label.
- Tab
- Opens/closes the tooltip without delay.
- EscEscape
- If open, closes the tooltip without delay.
- Enter
- When focus is on the trigger, activates it and closes the tooltip.
- Space
- When focus is on the trigger, activates it and closes the tooltip.
Demos
Sides
Four buttons, left, top, bottom and right, each show Add to library on that side. side on TooltipContent picks it, top by default. Pin a side when the default would cover what someone is working on, such as the first row of a table under a toolbar. When there isn't room, the tooltip flips to the opposite side.
Keyboard
An icon-only save button whose aria-label is Save Changes, with a tooltip that repeats the name beside an S in a Kbd. Use this to advertise a shortcut on a toolbar button. The Kbd is only text, so register the key handler yourself.
Disabled
The disabled button sits inside a span that acts as the trigger, because this registry's Button turns off pointer events while disabled. The span has role="button", aria-disabled and a place in the tab order, so hovering it or tabbing to it shows This feature is currently unavailable. A screen reader announces a disabled button with that reason as its description.
RTL
Add to library in Arabic, inside a wrapper with dir set to rtl. The first row picks physical sides, which stay put whatever the language. Radix UI only takes physical sides, so the second row maps the start of the line to right and its end to left itself.
FAQ
How do I change the Tooltip delay in React?
Set delayDuration on one Tooltip, or on the TooltipProvider for every tooltip inside it. This file's provider sets it to 0, where Radix UI's own default is 700 milliseconds.
A short delay suits a toolbar people scan with the pointer. A longer one keeps tooltips from flashing over a dense table as the pointer crosses it.
Do I need a TooltipProvider with Radix UI?
Yes. A Radix UI Tooltip throws when no TooltipProvider is above it, which is why every demo has one. Put a single provider near the root of your app, and its delayDuration and skipDelayDuration apply to every tooltip below it.
How do I change which side the Tooltip appears on?
Set side on TooltipContent: top (the default), right, bottom or left. align lines it up with the start, center or end of the trigger. sideOffset is the gap beyond the arrow, 4 pixels in this file, which Radix UI adds to the arrow's own height.
The Sides demo shows all four. When there isn't room on the side you picked, the tooltip flips to the opposite one.
Why doesn't my Tooltip show on a disabled button?
A disabled button can't take focus, and this registry's Button turns off pointer events while it's disabled, so neither hover nor focus reaches it. Wrap the button in a span and make the span the trigger, as the Disabled demo does.
Give that span role="button", aria-disabled set to true and a place in the tab order. Keyboard users then reach it too, and a screen reader announces a disabled button with the tooltip's text as its description.
Does a screen reader read the Tooltip text?
Yes, while it's open. Radix UI gives the tooltip role="tooltip" and points the trigger's aria-describedby at it, so the text is read as a description after the trigger's name. It only opens on keyboard focus or hover, so put anything essential in the trigger's own label as well.
Can I put a link or a button inside a Tooltip?
Not one that everyone can use. The tooltip closes as soon as focus leaves its trigger, so Tab never reaches a link inside it, and a click on the trigger closes it too.
Use a Popover when the extra content holds a link or a button, or a Hover Card for a preview the pointer can move into. Keep a tooltip to a few words of plain text, with at most a shortcut as in the Keyboard demo.
How do I keep a Tooltip open, or open it from code?
Pass open on Tooltip and update your state in onOpenChange, which receives the next state first. Setting defaultOpen instead opens it on the first render and leaves it uncontrolled.
Holding it open without a callback is the quickest way to style a tooltip without chasing it with the pointer. A product tour can also open one to point at a control.
Does the Tooltip work on mobile and touch screens?
Not as a hover hint. Touch screens have no hover, and Radix UI ignores touch pointers when it decides to open a tooltip, so a tap only activates the trigger.
Anything a phone user needs has to be in the trigger's label or on the page. For a hint people open on purpose with a tap, use a Toggle Tooltip.
API Reference
Tooltip
data-slot="tooltip"
open?boolean
Whether it's open. Pair with onOpenChange to control it.
defaultOpen?boolean
Whether it starts open, when you don't control open.
onOpenChange?{ bivarianceHack(open: boolean): void; }["bivarianceHack"]
Called when it opens or closes.
- Type
{ bivarianceHack(open: boolean): void; }["bivarianceHack"]
delayDuration?number
The duration from when the pointer enters the trigger until the tooltip gets opened. This will override the prop with the same name passed to Provider.
disableHoverableContent?boolean
When true, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.
TooltipTrigger
<button> data-slot="tooltip-trigger"
asChild?boolean
Merge props onto the child element instead of rendering a host.
TooltipArrow
<div> data-slot="tooltip-arrow"
--radix-tooltip-content-transform-originstringTooltipContent
<div> data-slot="tooltip-content"
align?(typeof ALIGN_OPTIONS)[number]
How it lines up with the trigger: start, center or end.
alignOffset?number
How far it shifts from its align position, in px.
arrowPadding?number
The space kept between the arrow and the content's corners, in px.
avoidCollisions?boolean
Whether it flips and shifts to stay in view.
collisionBoundary?Boundary | Boundary[]
The element or elements it stays inside. The viewport when unset.
- Type
Boundary | Boundary[]
collisionPadding?number | Partial<Record<Side, number>>
The distance it keeps from the boundary's edges, in px, or one per side.
- Type
number | Partial<Record<Side, number>>
forceMount?true
Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
hideWhenDetached?boolean
Whether it hides when its trigger is entirely out of view.
onEscapeKeyDown?{ bivarianceHack(event: KeyboardEvent): void; }["bivarianceHack"]
Event handler called when the escape key is down. Can be prevented.
- Type
{ bivarianceHack(event: KeyboardEvent): void; }["bivarianceHack"]
onPointerDownOutside?{ bivarianceHack(event: PointerDownOutsideEvent): void; }["bivarianceHack"]
Event handler called when the a pointerdown event happens outside of the Tooltip.
Can be prevented.
- Type
{ bivarianceHack(event: PointerDownOutsideEvent): void; }["bivarianceHack"]
side?(typeof SIDE_OPTIONS)[number]
The side of the trigger it opens on. It flips when there's no room, unless avoidCollisions is off.
sideOffset?number
The distance from the trigger, in px.
- Default
4
sticky?(typeof Sticky)[keyof typeof Sticky]
How it stays in view along its trigger: partial while the trigger is partly visible, always whatever the trigger does.
- Type
(typeof Sticky)[keyof typeof Sticky]
updatePositionStrategy?(typeof UpdatePositionStrategy)[keyof typeof UpdatePositionStrategy]
How often it updates its position: optimized, on layout changes, or always, every animation frame.
- Type
(typeof UpdatePositionStrategy)[keyof typeof UpdatePositionStrategy]
asChild?boolean
Merge props onto the child element instead of rendering a host.
className?string
Merged with the part's classes.
data-instant?string
Present when instant is true.
data-placementstring
The content's placement on its trigger, such as bottom-start.
data-side"top" | "right" | "bottom" | "left"
The side of the trigger the content sits on.
- Type
"top" | "right" | "bottom" | "left"
data-state"open" | "closed"
"open" or "closed".
- Type
"open" | "closed"
--radix-tooltip-content-transform-originstringTooltipProvider
data-slot="tooltip-provider"
delayDuration?number
The duration from when the pointer enters the trigger until the tooltip gets opened.
- Default
0
disableHoverableContent?boolean
When true, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.
skipDelayDuration?number
How much time a user has to enter another trigger without incurring a delay again.











