Hover Card
A card that shows users what is behind a link before they follow it.
A hover card shows a preview of the content behind a link, so users decide whether to follow the link without leaving the page. It opens when users rest the mouse pointer on the trigger or move focus to it with the keyboard. It stays open while the pointer is on the trigger or on the card, and it closes when the pointer or the focus leaves, when users press Escape or when they press outside of the card. Touch input doesn't open the hover card, so everything in it must also be available behind the link. The trigger is a link without styles of its own, so the examples render it as a Button with the link variant. The content is 16rem wide.
Usage
Examples
Trigger as Link
References in running text, such as a product in a note or a supplier in an order, usually lead to a page of their own. With an address in href, the trigger becomes a real link to that page, so users can follow it, open it in a new tab or copy its address, and the preview tells them beforehand what they will find there.
Top Side
Links in a footer or in the last rows of a long table sit close to the lower edge of the screen. There, side set to "top" opens the card above the trigger, where it can show its content in full.
Right Side
A navigation along the left edge of a screen, such as a list of stores, stacks its entries closely. Set to "right", side opens the card beside the trigger, so it covers none of the entries above or below.
Bottom Side
Users read a page from top to bottom, and most links leave enough room beneath them. The card therefore opens below the trigger by default, and side set to "bottom" states this explicitly. Where the space below runs short, it moves above the trigger on its own.
Left Side
Panels along the right edge of a screen, such as a list of open tasks, leave no room to their right. With the value "left", side opens the card toward the center of the screen, where it has the space it needs.
Open by Default
A preview can matter before users reach for it, for example when a delivery has changed since their last visit. Through defaultOpen, the card is already open when the page appears. Users close it as they would close any hover card, and afterwards it opens again whenever they return to the link.
Controlled
In some workflows, the application decides when a preview may appear, for example to keep it closed while users rearrange a list by dragging. Once it controls the card through open and onOpenChange, any part of the interface can open or close it as well.
API Reference
HoverCard
| Prop | open |
|---|---|
| Type | boolean |
| Default | – |
| Description | Sets whether the hover card is open and makes it controlled. Update it in onOpenChange. |
| Prop | defaultOpen |
|---|---|
| Type | boolean |
| Default | false |
| Description | Opens the hover card at first render. The hover card then tracks its open state itself. |
| Prop | onOpenChange |
|---|---|
| Type | (open: boolean, eventDetails: PreviewCardRootChangeEventDetails) => void |
| Default | – |
| Description | Runs when users open or close the hover card. It receives the open state that follows. |
| Prop | onOpenChangeComplete |
|---|---|
| Type | (open: boolean) => void |
| Default | – |
| Description | Runs after the hover card has opened or closed and its animations have finished. |
| Prop | triggerId |
|---|---|
| Type | string | null |
| Default | – |
| Description | Sets the ID of the trigger that a controlled hover card is associated with. A hover card without open doesn't need it. |
| Prop | defaultTriggerId |
|---|---|
| Type | string | null |
| Default | – |
| Description | Sets the ID of the trigger that the hover card is associated with when defaultOpen opens it at first render. |
| Prop | handle |
|---|---|
| Type | PreviewCardHandle<Payload> |
| Default | – |
| Description | Connects the hover card with triggers that are rendered outside of it. Create the handle with PreviewCard.createHandle() from @base-ui/react/preview-card. |
| Prop | actionsRef |
|---|---|
| Type | RefObject<PreviewCardRootActions | null> |
| Default | – |
| Description | Receives the functions close and unmount. close closes the hover card from code, and unmount removes it from the DOM after a closing animation that the code controls itself. |
| Prop | children |
|---|---|
| Type | ReactNode | ((arg: { payload: Payload | undefined }) => ReactNode) |
| Default | – |
| Description | Holds the parts of the hover card. A function receives the payload of the trigger that opened the hover card. |
HoverCardTrigger
| Prop | href |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the address that the trigger links to. The trigger renders a link and needs it, unless render replaces the link with another element. |
| Prop | delay |
|---|---|
| Type | number |
| Default | 600 |
| Description | Sets how many milliseconds the pointer or the focus must rest on the trigger before the hover card opens. |
| Prop | closeDelay |
|---|---|
| Type | number |
| Default | 300 |
| Description | Sets how many milliseconds the hover card stays open after the pointer has left the trigger and the content. |
| Prop | handle |
|---|---|
| Type | PreviewCardHandle<Payload> |
| Default | – |
| Description | Connects the trigger with a hover card that it is rendered outside of. Pass the same handle to HoverCard. |
| Prop | payload |
|---|---|
| Type | Payload |
| Default | – |
| Description | Passes a value to the hover card when this trigger opens it. A function as children of HoverCard receives it. |
| Prop | id |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the ID of the trigger element. triggerId and defaultTriggerId of HoverCard refer to it. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the trigger with another component. |
HoverCardContent
| Prop | side |
|---|---|
| Type | "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start" |
| Default | "bottom" |
| Description | Sets the side of the trigger that the content opens on. "inline-start" and "inline-end" follow the reading direction. The content moves to the opposite side when the chosen one has too little space. |
| Prop | sideOffset |
|---|---|
| Type | number | OffsetFunction |
| Default | 4 |
| Description | Sets the distance between the trigger and the content in pixels. A function receives the side, the alignment and the dimensions of the trigger and the content, and returns the distance. |
| Prop | align |
|---|---|
| Type | "start" | "center" | "end" |
| Default | "center" |
| Description | Sets where the content lines up with the trigger along the chosen side: at its start, its center or its end. |
| Prop | alignOffset |
|---|---|
| Type | number | OffsetFunction |
| Default | 4 |
| Description | Moves the content along the alignment axis by a number of pixels. A function receives the same data as the one for sideOffset and returns the offset. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the content with another component. |