suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • 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
  • Code Block
  • 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
  • Trace
  • 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>

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

$ 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
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react
  1. Copy and paste the following code into your project.
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}
    />
  )
  1. Update the import paths to match your project setup.

Usage

import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} 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>

Composition

Use the following composition to build a TooltipProvider:

TooltipProvider
└── Tooltip
    ├── TooltipTrigger
    └── TooltipContent

Examples

Sides

Set side on TooltipContent to place the tooltip on each of the four sides of its trigger.

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">
          <TooltipProvider>
            <Tooltip>
              <TooltipTrigger render={<Button variant="outline" />}>

With shortcut

Names an icon button and shows its keyboard shortcut by placing a Kbd inside TooltipContent.

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

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.

API Reference

TooltipProvider

Shares delay timing across the tooltips inside it.

PropTypeDefault
delaynumber0

Also accepts the props of the primitive part it wraps.

Wrap your app, or a toolbar of tooltips, in TooltipProvider. delay is how long to wait before opening a tooltip, in milliseconds. This wrapper sets it to 0, so tooltips open without waiting.

PropTypeDefault
delayDurationnumber0

Also accepts the props of the primitive part it wraps.

Wrap your app, or a toolbar of tooltips, in TooltipProvider. delayDuration is how long to wait before opening a tooltip, in milliseconds. This wrapper sets it to 0, so tooltips open without waiting. A Tooltip outside a TooltipProvider wraps itself in a provider with the default delay.

PropTypeDefault
delaynumber0
closeDelaynumber0

Wrap your app, or a toolbar of tooltips, in TooltipProvider. delay and closeDelay are how long to wait before opening and closing a tooltip, in milliseconds. This wrapper sets delay to 0, so tooltips open without waiting.

Tooltip

The root that holds a tooltip's open state.

Also accepts the props of the primitive part it wraps.

TooltipTrigger

The element that shows the tooltip on hover or focus.

Also accepts the props of the primitive part it wraps.

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.

TooltipContent

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

PropTypeDefault
side"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end""top"
sideOffsetnumber4
align"start" | "center" | "end""center"
alignOffsetnumber0
PropTypeDefault
side"top" | "right" | "bottom" | "left""top"
sideOffsetnumber4
align"start" | "center" | "end""center"
alignOffsetnumber0

Also accepts the props of the primitive parts it wraps.

The tooltip opens above the trigger by default, 4px away. sideOffset and alignOffset are in pixels; align lines the tooltip up with the trigger along its side. The label uses bg-foreground with text-background, so it inverts against the page in both light and dark appearances.

Each part sets a data-slot, such as tooltip-trigger or tooltip-content, for styling. The popup and arrow set data-side.

NextTracePreviousToggle Group

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • Sides
    • With shortcut
  5. 05Accessibility
  6. 06API Reference
    • TooltipProvider
    • Tooltip
    • TooltipTrigger
    • TooltipContent