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
<script lang="ts">
import { Button } from "@/components/ui/button"
import {
Tooltip, TooltipContent, TooltipTrigger,
} from "@/components/ui/tooltip"
</script>
<Tooltip><TooltipTrigger>{#snippet render({ props })}<Button {...props} variant="outline">Hover</Button>{/snippet}</TooltipTrigger><TooltipContent><p>Add to library</p></TooltipContent></Tooltip>Accessibility
The tooltip has role="tooltip" and stays in the page while it's hidden, so the trigger's aria-describedby points at it from the start, and a screen reader reads its text after the trigger's own name. Keyboard focus opens it at once and Escape closes it, leaving focus on the trigger. A trigger with no name of its own, such as an icon-only button without an aria-label, is named by the tooltip instead. Still give that button an aria-label, so its name doesn't change when someone edits the tooltip's text.
- 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. placement in the positioning prop on Tooltip picks it, and this file defaults to top. 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 Direction provider set to right to left, which also turns the tooltip's own text right to left. The first row picks physical sides, which stay put whatever the language. placement in positioning takes only 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 Svelte?
Set openDelay and closeDelay on one Tooltip, or delay and closeDelay on a TooltipProvider around a group. Without either, this file opens at once and closes after 100 milliseconds, where UI SDK's own defaults are 600 and 0.
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 UI SDK?
No. TooltipProvider in this file only hands its delay and closeDelay to the tooltips inside it, 0 and 100 milliseconds unless you set them, the same as a tooltip gets without one. UI SDK groups tooltips by itself: once one is open, or closed less than 400 milliseconds ago, the next one opens at once, and only one shows at a time.
How do I change which side the Tooltip appears on?
Pass positioning to Tooltip with a placement such as bottom or right-start, or set side on TooltipContent: top (the default), right, bottom, left, or inline-start and inline-end, which follow the tooltip's own direction. align, sideOffset (4 pixels in this file) and alignOffset fine-tune it, and a prop set on TooltipContent wins over positioning.
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, and not only while it's open: UI SDK keeps the tooltip in the page while it's hidden, with role="tooltip", and points the trigger's aria-describedby at it, so the text is read as a description after the trigger's name. A trigger with no name of its own, like an icon-only button without an aria-label, is named by the tooltip instead. It only shows 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. On UI SDK the pointer can move into it and the tooltip stays open, which still leaves out keyboard and touch users.
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 UI SDK 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
open?boolean
Whether the tooltip is open. Pass it to control the tooltip. Two-way with bind:open.
defaultOpen?boolean
Whether the tooltip starts open, when uncontrolled.
- Default
false
onOpenChange?(open: boolean, details: ChangeDetails<TooltipOpenChangeReason>) → void
Runs when the tooltip wants to open or close. details.reason says why, and details.cancel() stops it.
- Type
(open: boolean, details: ChangeDetails<TooltipOpenChangeReason>) → void- Parameters
open– booleandetails– ChangeDetails<TooltipOpenChangeReason>- Returns
void
closeDelay?number
Milliseconds before the tooltip closes once the pointer leaves the trigger and the tooltip. UI SDK's default: 0.
- Default
trigger.closeDelay ?? provider.closeDelay
closeOnPress?boolean
Whether pressing the trigger closes the tooltip. Set it to false to keep it open, like for a copy button whose tooltip turns into "Copied". UI SDK's default: true.
- Default
trigger.closeOnClick
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
controller?PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>
Opens, closes and inspects the tooltip from anywhere, and connects triggers outside it. Create one with createTooltipController().
- Type
PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>
debug?boolean
Logs every state change with its reason to the console, in development builds.
delay?number
Milliseconds the pointer rests on the trigger before the tooltip opens. While another tooltip is open, or was a moment ago, the next one opens at once, without a provider. UI SDK's default: 600.
- Default
trigger.delay ?? provider.delay
disabled?boolean
Stops the tooltip from opening. The trigger keeps working.
- Default
false
onOpenChangeComplete?(open: boolean) → void
Runs once the tooltip has finished opening or closing, after any animation.
- Parameters
open– boolean- Returns
void
onPayloadChange?(payload: unknown, details: ChangeDetails<TooltipPayloadChangeReason>) → void
Runs when the payload the content shows changes: a trigger with another payload opens the tooltip, or takes the open tooltip over, which fires no onOpenChange, and so does a controller's open({ payload }) on the open tooltip. details.cancel() keeps the previous payload.
- Type
(payload: unknown, details: ChangeDetails<TooltipPayloadChangeReason>) → void- Parameters
payload– unknowndetails– ChangeDetails<TooltipPayloadChangeReason>- Returns
void
shortcut?string
The keyboard shortcut of what the trigger does, like "mod+s", as a hint. A TooltipShortcut shows it, and the trigger gets aria-keyshortcuts. It doesn't bind the keys: the trigger's own shortcut, or registerShortcut, does.
toggleable?boolean
Whether pressing the trigger opens and closes the tooltip, so touch screens can show it too. For info buttons whose only job is the tip. The text is announced when a press opens it.
- Default
false
type?"description" | "label"
Whether the tooltip names its trigger ("label") or adds a description to it ("description"). By default it names a trigger that has no name of its own, like an icon button, and describes any other.
- Type
"description" | "label"
TooltipProvider
closeDelay?number
How long it waits to close after the pointer leaves, in milliseconds.
delay?number
- Default
0
timeout?number
Kept for the other bases' markup, and ignored: UI SDK opens a tooltip at once within a fixed 400ms of another closing, Base UI's default here.
TooltipTrigger
<button>
closeDelay?number
Milliseconds before closing once the pointer leaves, as the other bases set it here.
closeOnClick?boolean
Whether pressing the trigger closes the tooltip.
controller?PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>
Connects a trigger outside the tooltip, like one per table row, to the tooltip with this controller.
- Type
PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>
delay?number
Milliseconds the pointer rests on the trigger before opening.
disabled?boolean
Stops the tooltip from opening; the trigger itself keeps working.
payload?unknown
Data for the content to render when this trigger opens the tooltip, like the row it belongs to.
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
TooltipContent
<div> data-slot="tooltip-content"
align?Align
How the popup lines up with the anchor along that side. start and end follow the reading direction. How the tooltip lines up with the trigger along that side.
- Default
"center"
alignOffset?number
Shift along the anchor, in pixels. Shift along the trigger, in pixels.
- Default
0
anchor?string | Anchor | null
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.
- Type
string | Anchor | null
arrowPadding?number
Space to keep between the arrow and the popup's corners, in pixels.
- Default
6
collisionPadding?number
Space to keep from the viewport edges, in pixels.
- Default
8
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
hidden?boolean
Keeps the tooltip from opening, as the sidebar does while it's expanded.
- Default
false
side?TooltipSide
The side of the trigger it opens on. It flips when there's no room, unless avoidCollisions is off.
- Default
"top"
sideOffset?number
Gap between the anchor and the popup, in pixels. Gap between the trigger and the tooltip, in pixels.
- Default
4
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-align"start" | "center" | "end"
How the tooltip lines up with its trigger.
- Type
"start" | "center" | "end"
data-closed?string
Present while the tooltip is closed, including while it animates out.
data-ending-style?string
Present while the tooltip animates out. Style the state you animate to.
data-open?string
Present while the tooltip is open.
data-side"top" | "right" | "bottom" | "left"
Where the tooltip ended up, after flipping away from edges. Set on the arrow too.
- Type
"top" | "right" | "bottom" | "left"
data-starting-style?string
Present for the first frame. Style the state you animate from.
--anchor-heightstring
Height of the anchor.
--anchor-widthstring
Width of the anchor, usually the trigger. Use it to match widths.
--arrow-offsetstring
Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.
--available-heightstring
Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins.
--available-widthstring
Space beside the popup, up to the viewport edge. Not inherited either.
--transform-originstring
Where the content scales from, on its trigger's side.
TooltipArrow
<div> data-slot="tooltip-arrow"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-align"start" | "center" | "end"
How the tooltip lines up with its trigger.
- Type
"start" | "center" | "end"
data-arrow-clamped?string
Present on the arrow when it stops short of the middle of the trigger, held back by arrowPadding.
data-closed?string
Present while the tooltip is closed, including while it animates out.
data-open?string
Present while the tooltip is open.
data-side"top" | "right" | "bottom" | "left"
Where the tooltip ended up, after flipping away from edges. Set on the arrow too.
- Type
"top" | "right" | "bottom" | "left"











