> Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.

# Tooltip

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

## Features

- Provider to control display delay globally.

- Opens when the trigger is focused or hovered.

- Closes when the trigger is activated or when pressing escape.

- Supports custom timings.

## Anatomy

Import all parts and piece them together.

```jsx
import { Tooltip } from "@radix-solid/primitives";

export default () => <Tooltip.Provider>

		<Tooltip.Root>

			<Tooltip.Trigger />

			<Tooltip.Portal>

				<Tooltip.Content>

					<Tooltip.Arrow />

				</Tooltip.Content>

			</Tooltip.Portal>

		</Tooltip.Root>

	</Tooltip.Provider>;
```

## API Reference

### Provider

Wraps your app to provide global functionality to your tooltips.

| Prop                                                                                                                                  | Type      | Default |
| ------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------- |
| `delayDuration`The duration from when the mouse enters a tooltip trigger until the tooltip opens.                                     | `number`  | `700`   |
| `skipDelayDuration`How much time a user has to enter another trigger without incurring a delay again.                                 | `number`  | `300`   |
| `disableHoverableContent`Prevents `Tooltip.Content` from remaining open when hovering. Disabling this has accessibility consequences. | `boolean` | —       |

### Root

Contains all the parts of a tooltip.

| Prop                                                                                                                                                                    | Type       | Default |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------- |
| `defaultOpen`The open state of the tooltip when it is initially rendered. Use when you do not need to control its open state.                                           | `boolean`  | —       |
| `open`The controlled open state of the tooltip. Must be used in conjunction with `onOpenChange`.                                                                        | `boolean`  | —       |
| `onOpenChange`Event handler called when the open state of the tooltip changes.                                                                                          | `function` | —       |
| `delayDuration`Override the duration given to the \`Provider\` to customise the open delay for a specific tooltip.                                                      | `number`   | `700`   |
| `disableHoverableContent`Prevents `Tooltip.Content` from remaining open when hovering. Disabling this has accessibility consequences. Inherits from `Tooltip.Provider`. | `boolean`  | `false` |

### Trigger

The button that toggles the tooltip. By default, the `Tooltip.Content` will position itself against the trigger.

| Prop                                                                                                                                                                    | Type      | Default |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------- |
| `asChild`Render through a single-target factory, merging props and behavior with the chosen host. Read our [Composition](../guides/composition) guide for more details. | `boolean` | `false` |

| Data attribute | Values                                         |
| -------------- | ---------------------------------------------- |
| `[data-state]` | `"closed" \| "delayed-open" \| "instant-open"` |

### Portal

When used, portals the content part into the `body`.

| Prop                                                                                                                                                                                                          | Type          | Default         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | --------------- |
| `forceMount`Used to force mounting when more control is needed. Useful when controlling animation with Solid-compatible animation libraries. If used on this part, it will be inherited by `Tooltip.Content`. | `boolean`     | —               |
| `container`Specify a container element to portal the content into.                                                                                                                                            | `HTMLElement` | `document.body` |

### Content

The component that pops out when the tooltip is open.

| Prop                                                                                                                                                                                                                              | Type                | Default     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----------- |
| `asChild`Render through a single-target factory, merging props and behavior with the chosen host. Read our [Composition](../guides/composition) guide for more details.                                                           | `boolean`           | `false`     |
| `aria-label`By default, screenreaders will announce the content inside the component. If this is not descriptive enough, or you have content that cannot be announced, use `aria-label` as a more descriptive label.              | `string`            | —           |
| `onEscapeKeyDown`Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.                                                                                                         | `function`          | —           |
| `onPointerDownOutside`Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling `event.preventDefault`.                                                                | `function`          | —           |
| `forceMount`Used to force mounting when more control is needed. Useful when controlling animation with Solid-compatible animation libraries. It inherits from `Tooltip.Portal`.                                                   | `boolean`           | —           |
| `side`The preferred side of the trigger to render against when open. Will be reversed when collisions occur and `avoidCollisions` is enabled.                                                                                     | `enum`              | `"top"`     |
| `sideOffset`The distance in pixels from the trigger.                                                                                                                                                                              | `number`            | `0`         |
| `align`The preferred alignment against the trigger. May change when collisions occur.                                                                                                                                             | `enum`              | `"center"`  |
| `alignOffset`An offset in pixels from the `"start"` or `"end"` alignment options.                                                                                                                                                 | `number`            | `0`         |
| `avoidCollisions`When `true`, overrides the `side` and`align` preferences to prevent collisions with boundary edges.                                                                                                              | `boolean`           | `true`      |
| `collisionBoundary`The element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check.                                                        | `Boundary`          | `[]`        |
| `collisionPadding`The distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: `{ top: 20, left: 20 }`.                | `number \| Padding` | `0`         |
| `arrowPadding`The padding between the arrow and the edges of the content. If your content has `border-radius`, this will prevent it from overflowing the corners.                                                                 | `number`            | `0`         |
| `sticky`The sticky behavior on the align axis. `"partial"` will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst `"always"` will keep the content in the boundary regardless. | `enum`              | `"partial"` |
| `hideWhenDetached`Whether to hide the content when the trigger becomes fully occluded.                                                                                                                                            | `boolean`           | `false`     |

| Data attribute | Values                                         |
| -------------- | ---------------------------------------------- |
| `[data-state]` | `"closed" \| "delayed-open" \| "instant-open"` |
| `[data-side]`  | `"left" \| "right" \| "bottom" \| "top"`       |
| `[data-align]` | `"start" \| "end" \| "center"`                 |

| CSS Variable                               | Description                                                                  |
| ------------------------------------------ | ---------------------------------------------------------------------------- |
| `--radix-tooltip-content-transform-origin` | The `transform-origin` computed from the content and arrow positions/offsets |
| `--radix-tooltip-content-available-width`  | The remaining width between the trigger and the boundary edge                |
| `--radix-tooltip-content-available-height` | The remaining height between the trigger and the boundary edge               |
| `--radix-tooltip-trigger-width`            | The width of the trigger                                                     |
| `--radix-tooltip-trigger-height`           | The height of the trigger                                                    |

### Arrow

An optional arrow element to render alongside the tooltip. This can be used to help visually link the trigger with the `Tooltip.Content`. Must be rendered inside `Tooltip.Content`.

| Prop                                                                                                                                                                    | Type      | Default |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------- |
| `asChild`Render through a single-target factory, merging props and behavior with the chosen host. Read our [Composition](../guides/composition) guide for more details. | `boolean` | `false` |
| `width`The width of the arrow in pixels.                                                                                                                                | `number`  | `10`    |
| `height`The height of the arrow in pixels.                                                                                                                              | `number`  | `5`     |

## Examples

### Configure globally

Use the `Provider` to control `delayDuration` and `skipDelayDuration` globally.

```jsx
import { Tooltip } from "@radix-solid/primitives";

export default () => <Tooltip.Provider delayDuration={800} skipDelayDuration={500}>

		<Tooltip.Root>

			<Tooltip.Trigger>…</Tooltip.Trigger>

			<Tooltip.Content>…</Tooltip.Content>

		</Tooltip.Root>

		<Tooltip.Root>

			<Tooltip.Trigger>…</Tooltip.Trigger>

			<Tooltip.Content>…</Tooltip.Content>

		</Tooltip.Root>

	</Tooltip.Provider>;
```

### Show instantly

Use the `delayDuration` prop to control the time it takes for the tooltip to open.

```jsx
import { Tooltip } from "@radix-solid/primitives";

export default () => <Tooltip.Root delayDuration={0}>

		<Tooltip.Trigger>…</Tooltip.Trigger>

		<Tooltip.Content>…</Tooltip.Content>

	</Tooltip.Root>;
```

### Constrain the content size

You may want to constrain the width of the content so that it matches the trigger width. You may also want to constrain its height to not exceed the viewport.

We expose several CSS custom properties such as `--radix-tooltip-trigger-width` and `--radix-tooltip-content-available-height` to support this. Use them to constrain the content dimensions.

```jsx
// index.tsx

import { Tooltip } from "@radix-solid/primitives";

import "./styles.css";

export default () => <Tooltip.Root>

		<Tooltip.Trigger>…</Tooltip.Trigger>

		<Tooltip.Portal>

			<Tooltip.Content class="TooltipContent" sideOffset={5}>

				…

			</Tooltip.Content>

		</Tooltip.Portal>

	</Tooltip.Root>;
```

```css
/* styles.css */

.TooltipContent {

	width: var(--radix-tooltip-trigger-width);

	max-height: var(--radix-tooltip-content-available-height);

}
```

### Origin-aware animations

We expose a CSS custom property `--radix-tooltip-content-transform-origin`. Use it to animate the content from its computed origin based on `side`, `sideOffset`, `align`, `alignOffset` and any collisions.

```jsx
// index.tsx

import { Tooltip } from "@radix-solid/primitives";

import "./styles.css";

export default () => <Tooltip.Root>

		<Tooltip.Trigger>…</Tooltip.Trigger>

		<Tooltip.Content class="TooltipContent">…</Tooltip.Content>

	</Tooltip.Root>;
```

```css
/* styles.css */

.TooltipContent {

	transform-origin: var(--radix-tooltip-content-transform-origin);

	animation: scaleIn 0.5s ease-out;

}



@keyframes scaleIn {

	from {

		opacity: 0;

		transform: scale(0);

	}

	to {

		opacity: 1;

		transform: scale(1);

	}

}
```

### Collision-aware animations

We expose `data-side` and `data-align` attributes. Their values will change at runtime to reflect collisions. Use them to create collision and direction-aware animations.

```jsx
// index.tsx

import { Tooltip } from "@radix-solid/primitives";

import "./styles.css";

export default () => <Tooltip.Root>

		<Tooltip.Trigger>…</Tooltip.Trigger>

		<Tooltip.Content class="TooltipContent">…</Tooltip.Content>

	</Tooltip.Root>;
```

```css
/* styles.css */

.TooltipContent {

	animation-duration: 0.6s;

	animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);

}

.TooltipContent[data-side="top"] {

	animation-name: slideUp;

}

.TooltipContent[data-side="bottom"] {

	animation-name: slideDown;

}



@keyframes slideDown {

	from {

		opacity: 0;

		transform: translateY(-10px);

	}

	to {

		opacity: 1;

		transform: translateY(0);

	}

}



@keyframes slideUp {

	from {

		opacity: 0;

		transform: translateY(10px);

	}

	to {

		opacity: 1;

		transform: translateY(0);

	}

}
```

## Accessibility

### Keyboard Interactions

| Key      | Description                                |
| -------- | ------------------------------------------ |
| `Tab`    | Opens/closes the tooltip without delay.    |
| `Space`  | If open, closes the tooltip without delay. |
| `Enter`  | If open, closes the tooltip without delay. |
| `Escape` | If open, closes the tooltip without delay. |

## Custom APIs

Create your own API by abstracting the primitive parts into your own component.

### Abstract parts and introduce a content prop

This example abstracts all of the `Tooltip` parts and introduces a new `content` prop.

#### Usage

```jsx
import { Tooltip, TooltipProvider } from "./your-tooltip";

export default () => <TooltipProvider><Tooltip content="Tooltip content">

		{target => target("button", { children: "Tooltip trigger" })}

	</Tooltip></TooltipProvider>;
```

#### Implementation

Use the [`asChild` prop](/primitives/docs/guides/composition) to convert the trigger part into a slottable area. It will replace the trigger with the child that gets passed to it.

```jsx
import { omit, type ComponentProps, type Element } from "solid-js";

// your-tooltip.tsx



import { Tooltip as TooltipPrimitive, Slot } from "@radix-solid/primitives";

export const TooltipProvider = TooltipPrimitive.Provider;

type TooltipProps = Omit<Extract<ComponentProps<typeof TooltipPrimitive.Content>, { asChild?: false }>, "children"> &

  Pick<ComponentProps<typeof TooltipPrimitive.Root>, "open" | "defaultOpen" | "onOpenChange"> &

  { children: Slot.SlotRender; content: Element };

export function Tooltip(p: TooltipProps) {

  return <TooltipPrimitive.Root open={p.open} defaultOpen={p.defaultOpen} onOpenChange={p.onOpenChange}>

			<TooltipPrimitive.Trigger asChild>

				{p.children}

			</TooltipPrimitive.Trigger>

			<TooltipPrimitive.Content side="top" align="center" {...omit(p, "children", "content", "open", "defaultOpen", "onOpenChange")}>

				{p.content}

				<TooltipPrimitive.Arrow width={11} height={5} />

			</TooltipPrimitive.Content>

		</TooltipPrimitive.Root>;

}
```
