Preview Card
A popup that appears when a link is hovered, showing a preview for sighted users.
View as MarkdownThe principles of good typography remain into the digital age.
Anatomy
Import the component and assemble its parts:
import { PreviewCard } from '@base-ui-components/react/preview-card';
<PreviewCard.Root>
  <PreviewCard.Trigger />
  <PreviewCard.Portal>
    <PreviewCard.Backdrop />
    <PreviewCard.Positioner>
      <PreviewCard.Popup>
        <PreviewCard.Arrow />
      </PreviewCard.Popup>
    </PreviewCard.Positioner>
  </PreviewCard.Portal>
</PreviewCard.Root>API reference
Root
Groups all parts of the preview card. Doesn’t render its own HTML element.
defaultOpenboolean
false
defaultOpenboolean
false
- Name
- Description
- Whether the preview card is initially open. - To render a controlled preview card, use the - openprop instead.
- Type
- boolean | undefined
- Default
- false
openboolean
—
openboolean
—- Name
- Description
- Whether the preview card is currently open. 
- Type
- boolean | undefined
onOpenChangefunction
—
onOpenChangefunction
—- Name
- Description
- Event handler called when the preview card is opened or closed. 
- Type
- | (( open: boolean, eventDetails: PreviewCard.Root.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<PreviewCard.Root.Actions>
—
actionsRefRefObject<PreviewCard.Root.Actions>
—- Name
- Description
- A ref to imperative actions. - unmount: When specified, the preview card will not be unmounted when closed. Instead, the- unmountfunction must be called to unmount the preview card manually. Useful when the preview card's animation is controlled by an external library.
 
- Type
- | React.RefObject<PreviewCard.Root.Actions> | undefined
onOpenChangeCompletefunction
—
onOpenChangeCompletefunction
—- Description
- Event handler called after any animations complete when the preview card is opened or closed. 
- Type
- ((open: boolean) => void) | undefined
delaynumber
600
delaynumber
600
- Name
- Description
- How long to wait before the preview card opens. Specified in milliseconds. 
- Type
- number | undefined
- Default
- 600
closeDelaynumber
300
closeDelaynumber
300
- Name
- Description
- How long to wait before closing the preview card. Specified in milliseconds. 
- Type
- number | undefined
- Default
- 300
childrenReactNode
—
childrenReactNode
—- Name
- Type
- React.ReactNode
Trigger
A link that opens the preview card.
Renders an <a> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: PreviewCard.Trigger.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: PreviewCard.Trigger.State, ) => ReactElement)
data-popup-open
Present when the corresponding preview card is open.
Portal
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.
containerUnion
—
containerUnion
—- Name
- Description
- A parent element to render the portal element into. 
- Type
- | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: PreviewCard.Portal.State) => string)
keepMountedboolean
false
keepMountedboolean
false
- Name
- Description
- Whether to keep the portal mounted in the DOM while the popup is hidden. 
- Type
- boolean | undefined
- Default
- false
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: PreviewCard.Portal.State, ) => ReactElement)
Backdrop
An overlay displayed beneath the popup.
Renders a <div> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: PreviewCard.Backdrop.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: PreviewCard.Backdrop.State, ) => ReactElement)
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 is animating in.
data-ending-style
Present when the preview card is animating out.
Positioner
Positions the popup against the trigger.
Renders a <div> element.
collisionAvoidanceCollisionAvoidance
—
collisionAvoidanceCollisionAvoidance
—- Description
- Determines how to handle collisions when positioning the popup. 
- Type
- | { side?: 'none' | 'flip' align?: 'none' | 'shift' | 'flip' fallbackAxisSide?: 'none' | 'start' | 'end' } | { side?: 'none' | 'shift' align?: 'none' | 'shift' fallbackAxisSide?: 'none' | 'start' | 'end' } | undefined
- Example
- <Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
alignAlign
'center'
alignAlign
'center'
- Name
- Description
- How to align the popup relative to the specified side. 
- Type
- 'center' | 'start' | 'end' | undefined
- Default
- 'center'
alignOffsetnumber | OffsetFunction
0
alignOffsetnumber | OffsetFunction
0
- Name
- Description
- Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. - The function takes a - dataobject parameter with the following properties:- data.anchor: the dimensions of the anchor element with properties- widthand- height.
- data.positioner: the dimensions of the positioner element with properties- widthand- height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side.
 
- Type
- | number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined
- Default
- 0
- Example
- <Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide
'bottom'
sideSide
'bottom'
- Name
- Description
- Which side of the anchor element to align the popup against. May automatically change to avoid collisions. 
- Type
- | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | undefined
- Default
- 'bottom'
sideOffsetnumber | OffsetFunction
0
sideOffsetnumber | OffsetFunction
0
- Name
- Description
- Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. - The function takes a - dataobject parameter with the following properties:- data.anchor: the dimensions of the anchor element with properties- widthand- height.
- data.positioner: the dimensions of the positioner element with properties- widthand- height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side.
 
- Type
- | number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined
- Default
- 0
- Example
- <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber
5
arrowPaddingnumber
5
- Name
- Description
- Minimum distance to maintain between the arrow and the edges of the popup. - Use it to prevent the arrow element from hanging out of the rounded corners of a popup. 
- Type
- number | undefined
- Default
- 5
anchorUnion
—
anchorUnion
—- Name
- Description
- An element to position the popup against. By default, the popup will be positioned against the trigger. 
- Type
- | Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | undefined
collisionBoundaryBoundary
'clipping-ancestors'
collisionBoundaryBoundary
'clipping-ancestors'
- Description
- An element or a rectangle that delimits the area that the popup is confined to. 
- Type
- | Element | 'clipping-ancestors' | Element[] | Rect | undefined
- Default
- 'clipping-ancestors'
collisionPaddingPadding
5
collisionPaddingPadding
5
- Name
- Description
- Additional space to maintain from the edge of the collision boundary. 
- Type
- | { top?: number right?: number bottom?: number left?: number } | number | undefined
- Default
- 5
stickyboolean
false
stickyboolean
false
- Name
- Description
- Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. 
- Type
- boolean | undefined
- Default
- false
positionMethod'fixed' | 'absolute'
'absolute'
positionMethod'fixed' | 'absolute'
'absolute'
- Name
- Description
- Determines which CSS - positionproperty to use.
- Type
- 'fixed' | 'absolute' | undefined
- Default
- 'absolute'
trackAnchorboolean
true
trackAnchorboolean
true
- Name
- Description
- Whether the popup tracks any layout shift of its positioning anchor. 
- Type
- boolean | undefined
- Default
- true
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: PreviewCard.Positioner.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: PreviewCard.Positioner.State, ) => ReactElement)
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-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
--anchor-height
The anchor's height.
--anchor-width
The anchor's width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
Popup
A container for the preview card contents.
Renders a <div> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: PreviewCard.Popup.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: PreviewCard.Popup.State, ) => ReactElement)
data-open
Present when the preview card is open.
data-closed
Present when the preview card is closed.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the preview card is animating in.
data-ending-style
Present when the preview card is animating out.
Arrow
Displays an element positioned against the preview card anchor.
Renders a <div> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: PreviewCard.Arrow.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: PreviewCard.Arrow.State, ) => ReactElement)
data-open
Present when the preview card is open.
data-closed
Present when the preview card is closed.
data-uncentered
Present when the preview card arrow is uncentered.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.