suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
GitHubGet started
DocsComponentsPatternsInteractionsChartsBlocks
Components82
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Wheel Picker
  • Widget

suiss/ui · Component

Tooltip

A small label that appears next to an element on hover or keyboard focus.

Tooltip is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.

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

export default function TooltipDemo() {
  return (
    <TooltipProvider>
      <div className="p-12">
        <Tooltip>
          <TooltipTrigger render={<Button variant="outline" />}>
            Hover me
          </TooltipTrigger>
          <TooltipContent side="top">Add to library</TooltipContent>
        </Tooltip>
      </div>
    </TooltipProvider>
  )
}

Tooltip wraps the tooltip primitive of the chosen base. TooltipTrigger is the element that shows the tooltip, and TooltipContent renders the dark label with an arrow in a portal, positioned beside the trigger. TooltipProvider shares open delays across a group of tooltips.

Use tooltips to name icon-only buttons or show a keyboard shortcut. Keep the text short and don't put essential information or interactive content in a tooltip; use Popover for that.

Installation

CLI

$ pnpm dlx shadcn@latest add @esuiss/tooltip

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add tooltip

Manual

  1. Install the dependencies and add the cn helper:
$ pnpm add @base-ui/react
  1. Copy the source into components/ui/tooltip.tsx:
  1. Update the import paths to match your project.

Usage

import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } 
<








<








<






Set side on TooltipContent to place the tooltip on another side; it opens above the trigger by default, 4px away. Place a Kbd inside TooltipContent to show a shortcut.

Use the render prop on TooltipTrigger to render it as a Button.

Set asChild on TooltipTrigger to render a Button as the trigger.

The Button placed first inside Tooltip is the trigger.

Wrap your app, or a toolbar of tooltips, in TooltipProvider. This wrapper sets the provider's delay to 0, so tooltips open without waiting.

Examples

Sides

Places tooltips on each of the four sides of their triggers.

With shortcut

Names an icon button and shows its keyboard shortcut with Kbd.

API Reference

Anatomy4 parts
<TooltipProvider>
<Tooltip>
<TooltipTrigger />
<TooltipContent />
</Tooltip>
</TooltipProvider>
01

TooltipProvider

Shares delay timing across the tooltips inside it.

Also accepts the props of the primitive part it wraps.

02

Tooltip

The root that holds a tooltip's open state.

Also accepts the props of the primitive part it wraps.

03

TooltipTrigger

The element that shows the tooltip on hover or focus.

Also accepts the props of the primitive part it wraps.

04

TooltipContent

The positioned label with its arrow, rendered in a portal.

Also accepts the props of the primitive parts it wraps.

Accessibility

  • Tooltips open when the trigger is hovered or receives keyboard focus, and close when the pointer leaves.
  • Escape closes an open tooltip while focus stays on the trigger.
  • A tooltip doesn't name its trigger. Give icon-only triggers their own aria-label.

Notes

  • Parts carry data-slot attributes such as tooltip-trigger and tooltip-content; the popup and arrow set data-side.
  • The label uses bg-foreground with text-background, so it inverts against the page in both light and dark appearances.
  • TooltipContent accepts the positioner props side, sideOffset, align and alignOffset.
NextWheel PickerPreviousToggle Group

On this page

  1. 01Installation
    • CLI
    • Manual
  2. 02Usage
  3. 03Examples
    • Sides
    • With shortcut
  4. 04API Reference
    • TooltipProvider
    • Tooltip
    • TooltipTrigger
    • TooltipContent
  5. 05Accessibility
  6. 06Notes
from
"@/components/ui/tooltip"
TooltipProvider
>
<div className="p-12">
<Tooltip>
<TooltipTrigger render={<Button variant="outline" />}>
Hover me
</TooltipTrigger>
<TooltipContent side="top">Add to library</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
TooltipProvider
>
<div className="p-12">
<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline">Hover me</Button>
</TooltipTrigger>
<TooltipContent side="top">Add to library</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
TooltipProvider
>
<div className="p-12">
<Tooltip>
<Button variant="outline">Hover me</Button>
<TooltipContent side="top">Add to library</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
components/ui/tooltip.tsx
"use client"

import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip"
import { cn } from "@/lib/utils"

function TooltipProvider({
  delay = 0,
  ...props
}: TooltipPrimitive.Provider.Props) {
  return (
    <TooltipPrimitive.Provider
      data-slot="tooltip-provider"
      delay={delay}
      {...props}
    />
  )
import { Button } from "@/components/ui/button"
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/components/ui/tooltip"

export default function TooltipSides() {
  return (
    <TooltipProvider>
      <div className="p-12">
        <div className="grid grid-cols-2 place-items-center gap-x-24 gap-y-16">
          {(["top", "right", "left", "bottom"] as const).map((side) => (
            <TooltipProvider key={side}>
              <Tooltip>
                <TooltipTrigger render={<Button variant="outline" />}>
                  {side}
                </TooltipTrigger>
                <TooltipContent side={side}>Shown on the {side}</TooltipContent>
              </Tooltip>
            </TooltipProvider>
          ))}
        </div>
      </div>
    </TooltipProvider>
  )
}
import { PlusIcon } from "@phosphor-icons/react"
import { Button } from "@/components/ui/button"
import { Kbd } from "@/components/ui/kbd"
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/components/ui/tooltip"

export default function TooltipWithShortcut() {
  return (
    <TooltipProvider>
      <div className="p-12">
        <Tooltip>
          <TooltipTrigger
            render={
              <Button variant="outline" size="icon" aria-label="New file" />
            }
          >
            <PlusIcon />
          </TooltipTrigger>
          <TooltipContent side="top">
            New file
            <Kbd mod>N</Kbd>
          </TooltipContent>
        </Tooltip>
      </div>
    </TooltipProvider>
  )
}