PreviewCard

A card that previews a link on hover.

Base UI Preview CardSource

Open delay

Pass delay to PreviewCard.Trigger to set how long the hover lasts before the card opens. This demo uses 200 ms.

The code for this website is on GitHub.

Usage

These are defaults, not laws. Break one when you have a good reason, or when it makes the design more cohesive or more interesting.

  • Choose the component from the trigger and the content. A hover card on a trigger that is not a link hides its content from touch users, so use a popover there.
    ComponentTriggerContentOpens on
    TooltipAny controlA short text labelHover, focus
    PreviewCardA linkA rich preview of the link targetHover, focus
    Popover with openOnHoverNot a linkRich content, with or without controlsHover, click, tap, keyboard
  • Touch screens cannot hover, so do not put information in the card that the linked page does not have.
  • For an internal link, pass render={<GatsbyLink to="/path" />} to PreviewCard.Trigger.

API

Props that the library adds. Every part also takes all the Base UI props.

PreviewCard.Trigger

PropTypeDefaultDescription
appearance'link' | 'none''link'link styles the trigger as a text link. none adds no styles, for a trigger that has its own look, such as a chip.

PreviewCard.Popup

PropTypeDefaultDescription
sideOffsetnumber8The gap between the link and the card, in pixels.
containerHTMLElement | ShadowRoot | RefObject | null–The element that the card renders into. The default is the document body.