Hover Card
A card that appears when a user hovers over an element.
Anatomy
<HoverCard.Root>
<HoverCard.Trigger />
<HoverCard.Positioner>
<HoverCard.Arrow>
<HoverCard.ArrowTip />
</HoverCard.Arrow>
<HoverCard.Content />
</HoverCard.Positioner>
</HoverCard.Root>
Examples
Controlled
Use open and onOpenChange to control the open state.
Root Provider
Use RootProvider with the useHoverCard hook to access the state and methods from outside the component.
Delay
Use openDelay and closeDelay to set the open and close delays.
Positioning
Use positioning to set the placement and distance from the trigger.
Context
Read the state with HoverCard.Context or the useHoverCardContext hook.
Multiple Triggers
Give each HoverCard.Trigger a value to share one card across triggers. The card moves to the active trigger without
closing.
API Reference
Props
Root
| Prop | Default | Type |
|---|---|---|
closeDelay | 300 | numberThe duration from when the mouse leaves the trigger or content until the hover card closes. |
defaultOpen | booleanThe initial open state of the hover card when rendered. Use when you don't need to control the open state of the hover card. | |
defaultTriggerValue | stringThe initial trigger value when rendered. Use when you don't need to control the trigger value. | |
disabled | booleanWhether the hover card is disabled | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the popover. Useful for composition. | |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
lazyMount | false | booleanWhether to enable lazy mounting |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
onOpenChange | (details: OpenChangeDetails) => voidFunction called when the hover card opens or closes. | |
onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
onTriggerValueChange | (details: TriggerValueChangeDetails) => voidFunction called when the trigger value changes. | |
open | booleanThe controlled open state of the hover card | |
openDelay | 600 | numberThe duration from when the mouse enters the trigger until the hover card opens. |
positioning | PositioningOptionsThe user provided options used to position the popover content | |
present | booleanWhether the node is present (controlled by the user) | |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
triggerValue | stringThe controlled trigger value | |
unmountOnExit | false | booleanWhether to unmount on exit. |
Arrow
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-hover-card-arrow] | <uid> |
[data-state] | "open" | "closed" |
| CSS Variable | Description |
|---|---|
--arrow-size | The size of the arrow |
--arrow-size-half | Half the size of the arrow |
--arrow-background | Use this variable to style the arrow background |
--arrow-offset | The offset position of the arrow |
ArrowTip
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<HoverCardContentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-hover-card-content] | <uid> |
[data-value] | The value of the item |
[data-state] | "open" | "closed" |
[data-placement] | The placement of the content |
[data-side] | The side of the trigger that the content is positioned on |
[data-instant] | |
[data-activation-direction] | |
[data-nested] | popover |
[data-has-nested] | popover |
| CSS Variable | Description |
|---|---|
--layer-index | The index of the dismissable in the layer stack |
--nested-layer-count | The number of nested hover-cards |
Positioner
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<HoverCardPositionerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-hover-card-positioner] | <uid> |
[data-transitioning] | |
[data-instant] | |
[data-nested] | Present when the positioner is nested within another {{widget}} |
[data-has-nested] | Present when the positioner has nested {{widget}}s |
| CSS Variable | Description |
|---|---|
--reference-width | The width of the reference element |
--reference-height | The height of the root |
--available-width | The available width in viewport |
--available-height | The available height in viewport |
--x | The x position for transform |
--y | The y position for transform |
--transform-origin | The transform origin for animations |
RootProvider
| Prop | Default | Type |
|---|---|---|
value | UseHoverCardReturn | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
lazyMount | false | booleanWhether to enable lazy mounting |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
present | booleanWhether the node is present (controlled by the user) | |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
unmountOnExit | false | booleanWhether to unmount on exit. |
Trigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<HoverCardTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
value | stringThe value that identifies this specific trigger |
| Attribute | Description |
|---|---|
[data-hover-card-trigger] | <uid> |
[data-placement] | The placement of the trigger |
[data-side] | The side of the trigger that the trigger is positioned on |
[data-value] | The value of the item |
[data-current] | Present when current |
[data-state] | "open" | "closed" |
Context
API
| Property | Type |
|---|---|
open | booleanWhether the hover card is open |
setOpen | (open: boolean, reason?: OpenChangeReason) => voidFunction to open the hover card |
triggerValue | string | nullThe trigger value |
setTriggerValue | (value: string | null) => voidFunction to set the trigger value |
activationDirection | PopupActivationDirection | nullWhere the current trigger sits relative to the previous one, after switching triggers while open |
getContentValues | () => string[]Returns the trigger values whose content to render: the current one, plus the previous one while it animates out after a switch. Oldest first. |
reposition | (options?: Partial<PositioningOptions>) => voidFunction to reposition the popover |
getTriggerState | (props?: TriggerProps) => TriggerStateReturns the state of a specific trigger, including whether it's the currently active one |
getPositionerState | () => PositionerStateReturns the state of the positioner |
getContentState | (props?: ContentProps) => ContentStateReturns the state of the content |
getViewportState | () => ViewportStateReturns the state of the viewport |