Tooltip

A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.

Installation

npx shadcn@latest add tooltip

Usage

Import and use the tooltip component in your project.

import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/components/ui/tooltip"

export default function MyComponent() {
  return (
    <TooltipProvider>
      <Tooltip>
        <TooltipTrigger>Hover</TooltipTrigger>
        <TooltipContent>
          <p>Add to library</p>
        </TooltipContent>
      </Tooltip>
    </TooltipProvider>
  )
}

Examples

Default

A simple tooltip with text content.

With Icon Button

Tooltip on an icon button.

API Reference

Props available for the Tooltip component.

TooltipProvider

PropTypeDefaultDescription
delayDurationnumber700The delay in ms before the tooltip appears.
skipDelayDurationnumber300How long a user has to wait before another tooltip shows.

Tooltip

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the tooltip is open by default.
openboolean-Controlled open state.
onOpenChange(open: boolean) => void-Callback when the open state changes.

TooltipTrigger

PropTypeDefaultDescription
asChildbooleanfalseRender as child component.

TooltipContent

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""top"The preferred side of the trigger to render against.
sideOffsetnumber4The distance in pixels from the trigger.
align"start" | "center" | "end""center"The preferred alignment against the trigger.

Accessibility

Tooltip component follows WAI-ARIA tooltip pattern.

Keyboard Navigation

  • Tab: Shows the tooltip
  • Escape: Hides the tooltip

Content Guidelines

Keep tooltip content concise and informative. Tooltips should supplement, not replace, visible labels or instructions.