Tooltip
A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
This component uses Radix UI
shadcn/ui
This component uses shadcn/uiDocs
Loading...
import { Button, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from 'ui'
export function TooltipDemo() {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline">Hover</Button>
</TooltipTrigger>
<TooltipContent>
<p>Add to library</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)
}Installation
npx shadcn-ui@latest add tooltipUsage
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'<TooltipProvider>
<Tooltip>
<TooltipTrigger>Hover</TooltipTrigger>
<TooltipContent>
<p>Add to library</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>Inline text
Use a dotted underline and a help cursor (cursor-help) for a term with a short definition. Hover over the term or press Tab to focus it.
This app is requesting .
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from 'ui'
export function TooltipInlineDemo() {
return (
<TooltipProvider>
<p className="text-sm">
This app is requesting{' '}
<Tooltip>
<TooltipTrigger className="cursor-help underline decoration-dotted decoration-foreground-muted/50 hover:decoration-foreground-muted transition-colors underline-offset-[3px]">
database management
</TooltipTrigger>
<TooltipContent className="max-w-60">
Access database settings. Write access also allows the app to run SQL.
</TooltipContent>
</Tooltip>
.
</p>
</TooltipProvider>
)
}By default, the tooltip opens above the term. The tooltip automatically flips below the term when there isn’t enough room above it in the viewport.
In Studio, apply TOOLTIP_UNDERLINE_CLASS_NAME from @/components/ui/tooltip-styles to the trigger. Keep information people need to make a decision visible on the page.