# Tooltip

> Animated tooltip for React and shadcn with an optional keyboard shortcut; after the first, neighbours open instantly.

A short label that waits 400ms for the first trigger, then follows the pointer instantly across its neighbours. Enters 3px toward its trigger, shows an optional shortcut, never appears on touch.

- Tier: Free (MIT)
- Interaction: Hover
- Page: https://eased.dev/components/tooltip
- Installs: @base-ui/react
- Registry: https://eased.dev/r/tooltip.json

## Install

```bash
npx shadcn add https://eased.dev/r/tooltip.json
```

A short visual label for mouse and keyboard users on Base UI's Tooltip, with an optional keyboard shortcut. It never shows on touch.

## When to use

- Naming icon-only buttons in a toolbar: Bold, Italic, Insert link.
- Showing the keyboard shortcut for an action next to its name: Bold ⌘B.
- A row of controls people sweep across with the pointer: after the first tooltip, the rest appear at once.

## When not to use

- Anything people need in order to use the page, such as instructions, errors or why something is disabled: put it in the UI, because touch and screen reader users never see a tooltip.
- Content with links, buttons or more than a short line: use a [Popover](/components/popover).
- Explaining a disabled radio or setting: write it in the option's description, as [Radio Group](/components/radio-group) does.

## Usage

```tsx formatting-toolbar.tsx
import { Tooltip, TooltipProvider } from "@/components/eased/tooltip/tooltip";

export function FormattingToolbar() {
  return (
    <TooltipProvider>
      <Tooltip content="Bold" shortcut={["⌘", "B"]}>
        <button type="button" aria-label="Bold"><BoldIcon /></button>
      </Tooltip>
      <Tooltip content="Italic" shortcut={["⌘", "I"]}>
        <button type="button" aria-label="Italic"><ItalicIcon /></button>
      </Tooltip>
    </TooltipProvider>
  );
}
```

Wrap a toolbar, or your whole app, in one `TooltipProvider` so neighbouring tooltips share a delay group.

## Examples

### Below the trigger, with one key

A string `shortcut` shows a single key.

```tsx
<Tooltip content="Close panel" shortcut="Esc" side="bottom">
  <Button size="icon-sm" variant="ghost" aria-label="Close panel"><CloseIcon /></Button>
</Tooltip>
```

### Inside a dialog

Dialogs sit at z-index 50, the tooltip's default, so raise `zIndex` for a trigger inside one.

```tsx
<Tooltip content="Copy link" zIndex={60}>
  <Button size="icon-sm" aria-label="Copy link"><LinkIcon /></Button>
</Tooltip>
```

## API reference

### TooltipProvider

| Prop | Type | Default | Description |
|---|---|---|---|
| `delay` | `number` | `400` | How long the pointer must rest on the first trigger before its tooltip opens, ms. |
| `closeDelay` | `number` | `0` | How long a tooltip stays after the pointer leaves, ms. |
| `timeout` | `number` | `400` | After a tooltip closes, the next one within this window opens at once with no animation, ms. |

### Tooltip

| Prop | Type | Default | Description |
|---|---|---|---|
| `content` | `ReactNode` | | The label. Keep it short; the trigger still needs a matching `aria-label`. |
| `shortcut` | `string \| string[]` | | Keys shown after the label as Kbd caps: `["⌘", "B"]`, or `"Esc"` for one key. |
| `children` | `ReactElement` | | The trigger: one focusable element that accepts a ref, usually an icon button. |
| `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end"` | `"top"` | Preferred side; flips on collision. |
| `align` | `"start" \| "center" \| "end"` | `"center"` | |
| `sideOffset` | `number` | `6` | Gap to the trigger, px. |
| `delay` | `number` | the provider's | Rest time before opening, ms. Base UI's 600 outside a provider. |
| `closeDelay` | `number` | the provider's | |
| `closeOnClick` | `boolean` | `true` | Close when the trigger is clicked. |
| `open` / `defaultOpen` | `boolean` | | Controlled or uncontrolled open state. |
| `onOpenChange` | `(open: boolean) => void` | | |
| `disabled` | `boolean` | | Never open. |
| `zIndex` | `number` | `50` | Raise it inside a higher layer such as a dialog. |
| `className` | `string` | `""` | Appended to the tooltip's classes. |

The tooltip is at most 16rem wide and wraps longer text.

## Keyboard

| Key | Action |
|---|---|
| `Tab` | Focusing the trigger opens its tooltip. |
| `Esc` | Closes the tooltip. |

## Accessibility

- Tooltips are supplementary visual labels. Give the trigger an `aria-label` that matches `content`, so screen reader users get the same name.
- The shortcut caps are hidden from screen readers; the label already names the action.
- Base UI disables tooltips on touch, where there is no way to reveal one before tapping.
- Keyboard focus opens the tooltip as well as hover.

## Motion

The tooltip grows from its trigger: it scales from 0.97 at the trigger's origin and travels 3px toward its resting place on the snappy spring, while its opacity fades in over 150ms. It leaves in 100ms, travelling half as far, with no overshoot, and closing during the open turns around mid-flight. Inside a provider, the first tooltip waits 400ms; while the pointer sweeps on to neighbouring triggers, the rest appear and leave at once with no animation. Reduced motion keeps only a 100ms fade.

## Notes for AI

Use Tooltip to name icon-only buttons and show their shortcuts, with one `TooltipProvider` around the toolbar or app. The child must be a single focusable element that accepts a ref, with its own `aria-label`.

Do not put essential information, links or buttons in a tooltip: use a Popover or text in the UI instead. Do not add your own delay or animation; the provider and floating layer handle both.

## Related

- [Popover](/components/popover): an interactive panel that touch and screen reader users can reach.
- [Kbd](/components/kbd): the key caps the shortcut uses.

## Example

`components/eased/tooltip/tooltip-demo.tsx`

```tsx
"use client";

import { Toggle } from "@base-ui/react/toggle";
import { Toolbar } from "@base-ui/react/toolbar";
import type { ReactNode } from "react";
import { Button } from "../button/button";
import { DemoFrame } from "../lib/demo-frame";
import { Tooltip, TooltipProvider } from "./tooltip";

type Tool = { label: string; keys: string[]; icon: ReactNode; toggle?: boolean; pressed?: boolean };

const MARKS: Tool[] = [
  { label: "Bold", keys: ["⌘", "B"], icon: <BoldIcon />, toggle: true, pressed: true },
  { label: "Italic", keys: ["⌘", "I"], icon: <ItalicIcon />, toggle: true },
  { label: "Strikethrough", keys: ["⇧", "⌘", "X"], icon: <StrikeIcon />, toggle: true },
  { label: "Inline code", keys: ["⌘", "E"], icon: <CodeIcon />, toggle: true },
];

const BLOCKS: Tool[] = [
  { label: "Add link", keys: ["⌘", "K"], icon: <LinkIcon /> },
  { label: "Bulleted list", keys: ["⇧", "⌘", "8"], icon: <ListIcon />, toggle: true },
];

export function TooltipDemo() {
  return (
    <DemoFrame title="Release notes" meta="Draft">
      <TooltipProvider>
        <Toolbar.Root aria-label="Formatting" className="flex h-12 shrink-0 items-center gap-0.5 border-b border-line-subtle px-2">
          {MARKS.map((t) => (
            <Tool key={t.label} tool={t} />
          ))}
          <Toolbar.Separator className="mx-1.5 h-4 w-px shrink-0 bg-line" />
          {BLOCKS.map((t) => (
            <Tool key={t.label} tool={t} />
          ))}
          <div className="flex-1" />
          <Tool tool={{ label: "Undo", keys: ["⌘", "Z"], icon: <UndoIcon /> }} />
        </Toolbar.Root>
      </TooltipProvider>

      <article className="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-5">
        <h3 className="text-ui-md font-medium text-balance text-text">Eased 2.4: background sync</h3>
        <p className="text-ui text-pretty text-text-secondary">
          Offline edits now sync in the background. When two people change the same block, the{" "}
          <strong className="font-medium text-text">newest edit wins</strong> and the other is kept in history instead of
          asking you to choose.
        </p>
        <ul className="flex flex-col gap-1.5 text-ui text-text-secondary">
          {["Sync status lives in the title bar", "Conflicts open in a side-by-side diff", "Large files upload in parallel"].map(
            (line) => (
              <li key={line} className="flex gap-2">
                <span aria-hidden className="flex h-[1lh] shrink-0 items-center">
                  <span className="size-1 rounded-pill bg-text-muted" />
                </span>
                <span className="min-w-0">{line}</span>
              </li>
            ),
          )}
        </ul>
      </article>
    </DemoFrame>
  );
}

function Tool({ tool }: { tool: Tool }) {
  // Toolbar buttons sit side by side, so no extended hit area: it would cover the neighbours.
  const button = <Button variant="ghost" size="icon-sm" hitArea={false} className="data-pressed:bg-surface-active data-pressed:text-text" />;
  return (
    <Tooltip content={tool.label} shortcut={tool.keys} side="bottom">
      <Toolbar.Button aria-label={tool.label} render={tool.toggle ? <Toggle defaultPressed={tool.pressed} render={button} /> : button}>
        {tool.icon}
      </Toolbar.Button>
    </Tooltip>
  );
}

/* ---------- Icons: 16px, 1.5px stroke ---------- */

function Icon({ children }: { children: ReactNode }) {
  return (
    <svg
      viewBox="0 0 16 16"
      className="size-4 shrink-0"
      fill="none"
      stroke="currentColor"
      strokeWidth={1.5}
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden
    >
      {children}
    </svg>
  );
}

function BoldIcon() {
  return (
    <Icon>
      <path d="M4.75 3h4a2.5 2.5 0 0 1 0 5h-4zM4.75 8h4.75a2.5 2.5 0 0 1 0 5H4.75z" />
    </Icon>
  );
}

function ItalicIcon() {
  return (
    <Icon>
      <path d="M10 3h-3.5M9.5 13H6M9.75 3l-3.5 10" />
    </Icon>
  );
}

function StrikeIcon() {
  return (
    <Icon>
      <path d="M2.75 8h10.5M11 4.6C10.5 3.6 9.4 3 8 3 6.3 3 5 3.9 5 5.2c0 .9.5 1.5 1.3 1.9M5 11.4c.5 1 1.6 1.6 3 1.6 1.7 0 3-.9 3-2.3 0-.4-.1-.7-.3-1" />
    </Icon>
  );
}

function CodeIcon() {
  return (
    <Icon>
      <path d="M5.5 4.5 2 8l3.5 3.5M10.5 4.5 14 8l-3.5 3.5" />
    </Icon>
  );
}

function LinkIcon() {
  return (
    <Icon>
      <path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.5.5M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.5-.5" />
    </Icon>
  );
}

function ListIcon() {
  return (
    <Icon>
      <path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7" />
      <circle cx="3" cy="4.5" r=".6" fill="currentColor" />
      <circle cx="3" cy="8" r=".6" fill="currentColor" />
      <circle cx="3" cy="11.5" r=".6" fill="currentColor" />
    </Icon>
  );
}

function UndoIcon() {
  return (
    <Icon>
      <path d="M5 3.5 2.5 6 5 8.5" />
      <path d="M2.5 6h6.75a3.75 3.75 0 0 1 0 7.5H7" />
    </Icon>
  );
}
```
