# Tooltip

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

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).



<ComponentPreview name="tooltip-demo" />

## Installation [#installation]

<Tabs defaultValue="cli">
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    <Steps>
      <Step>
        Run the following command:
      </Step>

      ```bash
      npx shadcn@latest add https://shadcn-cssinjs.com/r/tooltip.json
      ```

      <Step>
        Add the 

        `TooltipProvider`

         to the root of your app.
      </Step>

      ```tsx title="app/layout.tsx" showLineNumbers {1,7}
      import { TooltipProvider } from "@/components/ui/tooltip";

      export default function RootLayout({ children }) {
        return (
          <html lang="en">
            <body>
              <TooltipProvider>{children}</TooltipProvider>
            </body>
          </html>
        );
      }
      ```
    </Steps>
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      pnpm add @base-ui/react @stylexjs/stylex
      ```

      <Step>
        Make sure [StyleX is configured](/docs/installation) and the design tokens are
        installed.
      </Step>

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource name="tooltip" title="tooltip.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>

      <Step>
        Add the 

        `TooltipProvider`

         to the root of your app.
      </Step>

      ```tsx title="app/layout.tsx" showLineNumbers {1,7}
      import { TooltipProvider } from "@/components/ui/tooltip";

      export default function RootLayout({ children }) {
        return (
          <html lang="en">
            <body>
              <TooltipProvider>{children}</TooltipProvider>
            </body>
          </html>
        );
      }
      ```
    </Steps>
  </TabsContent>
</Tabs>

## Usage [#usage]

```tsx showLineNumbers
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "@/components/ui/tooltip";
```

```tsx showLineNumbers
<Tooltip>
  <TooltipTrigger>Hover</TooltipTrigger>
  <TooltipContent>
    <p>Add to library</p>
  </TooltipContent>
</Tooltip>
```

## Composition [#composition]

Use the following composition to build a `Tooltip`:

```text
Tooltip
├── TooltipTrigger
└── TooltipContent
```

## Side [#side]

Use the `side` prop to change the position of the tooltip.

<ComponentPreview name="tooltip-sides" />

## With Keyboard Shortcut [#with-keyboard-shortcut]

<ComponentPreview name="tooltip-keyboard" />

## Disabled Button [#disabled-button]

Show a tooltip on a disabled button by wrapping it with a span.

<ComponentPreview name="tooltip-disabled" />

## RTL [#rtl]

To enable RTL support in shadcn/ui, see the [RTL configuration guide](/docs/rtl).

<ComponentPreview name="tooltip-rtl" direction="rtl" />

## API Reference [#api-reference]

See the [Base UI Tooltip](https://base-ui.com/react/components/tooltip#api-reference) documentation.
