Hover Card

A card that appears when a user hovers over an element.

Loading...

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

PropDefaultType
closeDelay300
number

The duration from when the mouse leaves the trigger or content until the hover card closes.

defaultOpen
boolean

The 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
string

The initial trigger value when rendered. Use when you don't need to control the trigger value.

disabled
boolean

Whether the hover card is disabled

hideMode'display-none'
HideMode

How 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
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the popover. Useful for composition.

immediate
boolean

Whether to synchronize the present change immediately or defer it to the next frame

lazyMountfalse
boolean

Whether to enable lazy mounting

onEnterComplete
VoidFunction

Function called when the animation ends in the open state

onExitComplete
VoidFunction

Function called when the animation ends in the closed state

onFocusOutside
(event: FocusOutsideEvent) => void

Function called when the focus is moved outside the component

onInteractOutside
(event: InteractOutsideEvent) => void

Function called when an interaction happens outside the component

onOpenChange
(details: OpenChangeDetails) => void

Function called when the hover card opens or closes.

onPointerDownOutside
(event: PointerDownOutsideEvent) => void

Function called when the pointer is pressed down outside the component

onTriggerValueChange
(details: TriggerValueChangeDetails) => void

Function called when the trigger value changes.

open
boolean

The controlled open state of the hover card

openDelay600
number

The duration from when the mouse enters the trigger until the hover card opens.

positioning
PositioningOptions

The user provided options used to position the popover content

present
boolean

Whether the node is present (controlled by the user)

skipAnimationOnMountfalse
boolean

Whether to allow the initial presence animation.

triggerValue
string

The controlled trigger value

unmountOnExitfalse
boolean

Whether to unmount on exit.

Arrow

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-hover-card-arrow]<uid>
[data-state]"open" | "closed"
CSS VariableDescription
--arrow-sizeThe size of the arrow
--arrow-size-halfHalf the size of the arrow
--arrow-backgroundUse this variable to style the arrow background
--arrow-offsetThe offset position of the arrow

ArrowTip

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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 VariableDescription
--layer-indexThe index of the dismissable in the layer stack
--nested-layer-countThe number of nested hover-cards

Positioner

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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 VariableDescription
--reference-widthThe width of the reference element
--reference-heightThe height of the root
--available-widthThe available width in viewport
--available-heightThe available height in viewport
--xThe x position for transform
--yThe y position for transform
--transform-originThe transform origin for animations

RootProvider

PropDefaultType
value
UseHoverCardReturn

hideMode'display-none'
HideMode

How 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
boolean

Whether to synchronize the present change immediately or defer it to the next frame

lazyMountfalse
boolean

Whether to enable lazy mounting

onEnterComplete
VoidFunction

Function called when the animation ends in the open state

onExitComplete
VoidFunction

Function called when the animation ends in the closed state

present
boolean

Whether the node is present (controlled by the user)

skipAnimationOnMountfalse
boolean

Whether to allow the initial presence animation.

unmountOnExitfalse
boolean

Whether to unmount on exit.

Trigger

Defines the <button> element.

AttributeDefaultType
asChild
boolean

Use 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
string

The value that identifies this specific trigger

AttributeDescription
[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

PropertyType
open
boolean

Whether the hover card is open

setOpen
(open: boolean, reason?: OpenChangeReason) => void

Function to open the hover card

triggerValue
string | null

The trigger value

setTriggerValue
(value: string | null) => void

Function to set the trigger value

activationDirection
PopupActivationDirection | null

Where 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>) => void

Function to reposition the popover

getTriggerState
(props?: TriggerProps) => TriggerState

Returns the state of a specific trigger, including whether it's the currently active one

getPositionerState
() => PositionerState

Returns the state of the positioner

getContentState
(props?: ContentProps) => ContentState

Returns the state of the content

getViewportState
() => ViewportState

Returns the state of the viewport