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

# Hover Card

For sighted users to preview content available behind a link.

## Features

- Can be controlled or uncontrolled.

- Customize side, alignment, offsets, collision handling.

- Optionally render a pointing arrow.

- Supports custom open and close delays.

- Ignored by screen readers.

## Anatomy

Import all parts and piece them together.

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

export default () => <HoverCard.Root>

		<HoverCard.Trigger />

		<HoverCard.Portal>

			<HoverCard.Content>

				<HoverCard.Arrow />

			</HoverCard.Content>

		</HoverCard.Portal>

	</HoverCard.Root>;
```

## API Reference

### Root

Contains all the parts of a hover card.

| Prop                                                                                                                             | Type       | Default |
| -------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------- |
| `defaultOpen`The open state of the hover card when it is initially rendered. Use when you do not need to control its open state. | `boolean`  | —       |
| `open`The controlled open state of the hover card. Must be used in conjunction with `onOpenChange`.                              | `boolean`  | —       |
| `onOpenChange`Event handler called when the open state of the hover card changes.                                                | `function` | —       |
| `openDelay`The duration from when the mouse enters the trigger until the hover card opens.                                       | `number`   | `700`   |
| `closeDelay`The duration from when the mouse leaves the trigger or content until the hover card closes.                          | `number`   | `300`   |

### Trigger

The link that opens the hover card when hovered.

| 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]` | `"open" \| "closed"` |

### 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 `HoverCard.Content`. | `boolean`     | —               |
| `container`Specify a container element to portal the content into.                                                                                                                                              | `HTMLElement` | `document.body` |

### Content

The component that pops out when the hover card 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`     |
| `forceMount`Used to force mounting when more control is needed. Useful when controlling animation with Solid-compatible animation libraries. It inherits from `HoverCard.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`              | `"bottom"`  |
| `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]` | `"open" \| "closed"`                     |
| `[data-side]`  | `"left" \| "right" \| "bottom" \| "top"` |
| `[data-align]` | `"start" \| "end" \| "center"`           |

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

### Arrow

An optional arrow element to render alongside the hover card. This can be used to help visually link the trigger with the `HoverCard.Content`. Must be rendered inside `HoverCard.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

### Show instantly

Use the `openDelay` prop to control the time it takes for the hover card to open.

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

export default () => <HoverCard.Root openDelay={0}>

		<HoverCard.Trigger>…</HoverCard.Trigger>

		<HoverCard.Content>…</HoverCard.Content>

	</HoverCard.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-hover-card-trigger-width` and `--radix-hover-card-content-available-height` to support this. Use them to constrain the content dimensions.

```jsx
// index.tsx

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

import "./styles.css";

export default () => <HoverCard.Root>

		<HoverCard.Trigger>…</HoverCard.Trigger>

		<HoverCard.Portal>

			<HoverCard.Content class="HoverCardContent" sideOffset={5}>

				…

			</HoverCard.Content>

		</HoverCard.Portal>

	</HoverCard.Root>;
```

```css
/* styles.css */

.HoverCardContent {

	width: var(--radix-hover-card-trigger-width);

	max-height: var(--radix-hover-card-content-available-height);

}
```

### Origin-aware animations

We expose a CSS custom property `--radix-hover-card-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 { HoverCard } from "@radix-solid/primitives";

import "./styles.css";

export default () => <HoverCard.Root>

		<HoverCard.Trigger>…</HoverCard.Trigger>

		<HoverCard.Content class="HoverCardContent">…</HoverCard.Content>

	</HoverCard.Root>;
```

```css
/* styles.css */

.HoverCardContent {

	transform-origin: var(--radix-hover-card-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 { HoverCard } from "@radix-solid/primitives";

import "./styles.css";

export default () => <HoverCard.Root>

		<HoverCard.Trigger>…</HoverCard.Trigger>

		<HoverCard.Content class="HoverCardContent">…</HoverCard.Content>

	</HoverCard.Root>;
```

```css
/* styles.css */

.HoverCardContent {

	animation-duration: 0.6s;

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

}

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

	animation-name: slideUp;

}

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

	animation-name: slideDown;

}



@keyframes slideUp {

	from {

		opacity: 0;

		transform: translateY(10px);

	}

	to {

		opacity: 1;

		transform: translateY(0);

	}

}



@keyframes slideDown {

	from {

		opacity: 0;

		transform: translateY(-10px);

	}

	to {

		opacity: 1;

		transform: translateY(0);

	}

}
```

## Accessibility

The hover card is intended for sighted users only, the content will be inaccessible to keyboard users.

### Keyboard Interactions

| Key     | Description                  |
| ------- | ---------------------------- |
| `Tab`   | Opens/closes the hover card. |
| `Enter` | Opens the hover card link    |
