Skip to content

Preview Card

A hover preview of a link destination for sighted pointer and keyboard users.

The latest workflow revision was published by Ada Lovelace two hours ago.

hero.tsx

Usage guidelines

  • Use PreviewCard as a non-interactive enhancement for a link destination, such as a member profile or a cited document. Use Popover when opening the popup is the trigger's purpose or its content must be reachable on touch and with assistive technology.
  • Keep the link as the only accessible interface. The popup is not reachable on touch or by screen readers, so everything it shows also exists at the linked destination.
  • Keep the popup free of buttons, links and fields. Users cannot move focus into it.
  • PreviewCardTrigger renders a real link. Give it an href and visible link text, which also names it.
  • Several links can share one root through a handle from createPreviewCardHandle. Each trigger passes its item as payload, and the root's function child reads the payload of the hovered or focused link.
  • The default delays suit links in prose. Shorten delay and closeDelay on the trigger for dense lists where users scan many links in a row.

Anatomy

tsx
tsx

PreviewCardContent bundles the portal, positioner and styled popup and takes side, align and their offsets. Compose PreviewCardPortal, PreviewCardPositioner and PreviewCardPopup directly, with PreviewCardViewport, only when a surface needs more than those options.

Examples

Two citations in a sentence share one root through a handle. Each link passes its document as payload.

The answer cites Refund policy.pdf and Shipping guide.md from the Customer support knowledge base.

detached-triggers.tsx

Shorter delays in a list

A member list shares one root through a handle and sets shorter delay and closeDelay values on each trigger, so a single preview follows the pointer smoothly while scanning down the list.

delay.tsx

Keyboard

KeyAction
TabFocusing the link opens the preview after the trigger's delay. Moving focus away closes it.
EscapeCloses the preview. Focus stays on the link.

API reference

PreviewCard

Groups all parts of a hover- and focus-triggered preview card for a link. Doesn't render its own HTML element.

Keep the preview non-interactive and duplicate any essential content at the linked destination, since touch and screen-reader users cannot reach it. Use Popover when opening the popup is the trigger's purpose or when its content must be accessible across input modes.

Base UI PreviewCard.Root docs

PreviewCardContent

A styled preview card surface bundled with a portal and positioner. Renders a <div> element.

Base UI PreviewCard.Popup docs

Props
PropTypeDefaultDetails
sideOffsetnumber | OffsetFunction8
children requiredReact.ReactNodeNo default
Base UI PreviewCard.Popup docs
Data attributes
AttributeDescription
data-open

Present when the preview card is open.

data-closed

Present when the preview card is closed.

data-starting-style

Present when the preview card begins animating in.

data-ending-style

Present when the preview card is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the trigger.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

CSS variables
VariableDescription
--available-width

Values: number

The available width between the trigger and the edge of the viewport.

--available-height

Values: number

The available height between the trigger and the edge of the viewport.

--anchor-width

Values: number

The anchor's width.

--anchor-height

Values: number

The anchor's height.

--transform-origin

Values: string

The coordinates that this element is anchored to. Used for animations and transitions.

--positioner-width

Values: number

The width of the preview card's positioner. It is important to set width to this value when using CSS to animate size changes.

--positioner-height

Values: number

The height of the preview card's positioner. It is important to set height to this value when using CSS to animate size changes.

PreviewCardPopup

A container for the preview card contents. Renders a <div> element.

Base UI PreviewCard.Popup docs

Data attributes
AttributeDescription
data-open

Present when the preview card is open.

data-closed

Present when the preview card is closed.

data-starting-style

Present when the preview card begins animating in.

data-ending-style

Present when the preview card is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the trigger.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

PreviewCardPortal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

Base UI PreviewCard.Portal docs

PreviewCardPositioner

Positions the popup against the trigger. Renders a <div> element.

Base UI PreviewCard.Positioner docs

Props
PropTypeDefaultDetails
sideOffsetnumber | OffsetFunction8
Base UI PreviewCard.Positioner docs
Data attributes
AttributeDescription
data-open

Present when the preview card is open.

data-closed

Present when the preview card is closed.

data-anchor-hidden

Present when the anchor is hidden.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the trigger.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

CSS variables
VariableDescription
--available-width

Values: number

The available width between the trigger and the edge of the viewport.

--available-height

Values: number

The available height between the trigger and the edge of the viewport.

--anchor-width

Values: number

The anchor's width.

--anchor-height

Values: number

The anchor's height.

--transform-origin

Values: string

The coordinates that this element is anchored to. Used for animations and transitions.

--positioner-width

Values: number

The width of the preview card's positioner. It is important to set width to this value when using CSS to animate size changes.

--positioner-height

Values: number

The height of the preview card's positioner. It is important to set height to this value when using CSS to animate size changes.

PreviewCardTrigger

A link that opens the preview card. Renders an <a> element.

Base UI PreviewCard.Trigger docs

Data attributes
AttributeDescription
data-popup-open

Present when the corresponding preview card is open.

PreviewCardViewport

A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content changes based on the trigger, and switching between them is animated. Renders a <div> element.

Base UI PreviewCard.Viewport docs

Data attributes
AttributeDescription
data-current

Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.

data-previous

Applied to the direct child of the viewport that contains the exiting content when transitions are present.

data-activation-direction

Values: `${'left' | 'right' | ''} ${'down' | 'up' | ''}`

Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.

data-transitioning

Indicates that the viewport is currently transitioning between old and new content.

data-instant

Values: 'dismiss' | 'focus'

Present if animations should be instant.

CSS variables
VariableDescription
--popup-width

The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

--popup-height

The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

createPreviewCardHandle

Creates a new handle to connect a PreviewCard.Root with detached PreviewCard.Trigger components.

Returns

BasePreviewCard.Handle<Payload>
Return properties
MemberTypeDescription
open required(triggerId: string) => void

Opens the preview card and associates it with the trigger with the given id.

This method should only be called in an event handler or an effect (not during rendering).

close required() => void

Closes the preview card.

This method should only be called in an event handler or an effect (not during rendering).

isOpen requiredboolean

Whether the preview card is currently open. Returns false while no root is attached to the handle.