Skip to content
All components
Overlays

Hover card

Preview what is behind a link, such as a person, a page or a record, when the pointer rests on it or the link receives focus, without leaving the page.

A supplemental link preview that opens on pointer hover or trigger focus.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add hover-card

Then import it from @/components/ui/hover-card. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Profile preview

Preview a person behind a profile link without leaving the page. The link destination still holds every detail shown in the card.

"use client"

import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import {
  HoverCard,
  HoverCardContent,
  HoverCardTrigger,
} from "@/components/ui/hover-card"

export function HoverCardProfilePreview() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <HoverCard>
        <HoverCardTrigger href="/people/ada" className="text-label-sm text-primary-base underline decoration-dotted">
          @ada
        </HoverCardTrigger>
        <HoverCardContent className="w-72">
          <div className="flex items-start gap-3">
            <Avatar size="md">
              <AvatarFallback>AL</AvatarFallback>
            </Avatar>
            <div className="min-w-0">
              <p className="text-label-sm text-strong-950">Ada Lovelace</p>
              <p className="text-paragraph-sm text-sub-600">
                Design engineer. Maintains the form components.
              </p>
              <p className="mt-2 text-label-xs text-sub-600">Joined March 2024</p>
            </div>
          </div>
        </HoverCardContent>
      </HoverCard>
    </div>
  )
}

Top with delays

Open the preview above the link with longer open and close delays. openDelay avoids accidental previews while the pointer passes over; closeDelay lets it travel into the card.

"use client"

import {
  HoverCard,
  HoverCardContent,
  HoverCardTrigger,
} from "@/components/ui/hover-card"

export function HoverCardTopWithDelays() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <HoverCard openDelay={500} closeDelay={200}>
        <HoverCardTrigger href="/changelog" className="text-label-sm text-primary-base underline decoration-dotted">
          release notes
        </HoverCardTrigger>
        <HoverCardContent side="top" align="start">
          <p className="text-label-sm text-strong-950">Version 2.4</p>
          <p className="mt-1 text-paragraph-sm text-sub-600">
            Adds keyboard shortcuts to menus and fixes focus return in sheets.
          </p>
        </HoverCardContent>
      </HoverCard>
    </div>
  )
}

Inline link

Attach a preview to a link inside running text with asChild. The existing anchor keeps its href and reading flow.

"use client"

import {
  HoverCard,
  HoverCardContent,
  HoverCardTrigger,
} from "@/components/ui/hover-card"

export function HoverCardInlineLink() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <p className="max-w-sm text-paragraph-sm text-sub-600">
        Every item is described in the{" "}
        <HoverCard>
          <HoverCardTrigger asChild>
            <a href="/docs/registry" className="text-primary-base underline decoration-dotted">
              registry guide
            </a>
          </HoverCardTrigger>
          <HoverCardContent>
            <p className="text-paragraph-sm text-sub-600">
              How a component travels from the registry into your project.
            </p>
          </HoverCardContent>
        </HoverCard>
        , which lists the files each one installs.
      </p>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

HoverCard

Preview supplemental content near a hover target.

HoverCard props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (5)
HoverCard inherited props
PropTypeDefaultDescription
openboolean | undefined—Controlled visibility state. Pair with onOpenChange so requested state changes can be applied.
defaultOpenboolean | undefined—Initial uncontrolled visibility state. Later changes use the primitive's controls or controlled open API.
onOpenChange((open: boolean) => void) | undefined—Receive the requested open state. Apply it to open when controlled.
openDelaynumber | undefined—Delay before hover-triggered supporting content opens.
closeDelaynumber | undefined—Delay before hover-triggered supporting content closes.

HoverCardContent

Content region within the root composition. Keep required providers, labels and related controls from the complete example.

HoverCardContent props
PropTypeDefaultDescription
forceMounttrue | undefined—Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
onEscapeKeyDown((event: KeyboardEvent) => void) | undefined—Event handler called when the escape key is down. Can be prevented.
onPointerDownOutside((event: CustomEvent<{ originalEvent: PointerEvent; }>) => void) | undefined—Event handler called when the a pointerdown event happens outside of the HoverCard. Can be prevented.
onFocusOutside((event: CustomEvent<{ originalEvent: FocusEvent; }>) => void) | undefined—Event handler called when the focus moves outside of the HoverCard. Can be prevented.
onInteractOutside((event: CustomEvent<{ originalEvent: PointerEvent; }> | CustomEvent<{ originalEvent: FocusEvent; }>) => void) | undefined—Event handler called when an interaction happens outside the HoverCard. Specifically, when a pointerdown event happens outside or focus moves outside of it. Can be prevented.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (25)
HoverCardContent inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
side"top" | "right" | "bottom" | "left" | undefined—Preferred side relative to the trigger. Collision handling can adjust the final placement where supported.
sideOffsetnumber | undefined6Spacing between the floating content and its trigger along the placement axis.
align"center" | "start" | "end" | undefined"center"Alignment of floating content relative to its trigger, using the supported source values.
alignOffsetnumber | undefined—Offset from the selected floating-content alignment.
arrowPaddingnumber | undefined—Minimum spacing between a floating arrow and the content's edges.
avoidCollisionsboolean | undefined—Allow floating content to adjust placement to avoid its collision boundary.
collisionBoundary(Element | null) | (Element | null)[] | undefined—Element or elements used as the boundary for floating-content collision checks.
collisionPaddingnumber | Partial<Record<"top" | "right" | "bottom" | "left", number>> | undefined—Space reserved between floating content and its collision boundary.
sticky("partial" | "always") | undefined—How floating content remains attached to its trigger while collision positioning is constrained.
hideWhenDetachedboolean | undefined—Hide floating content when its trigger becomes detached from the positioning boundary.
updatePositionStrategy("always" | "optimized") | undefined—Optimized or continuous updates to floating-content positioning, as supported by the primitive.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

HoverCardTrigger

Interactive control that opens or toggles the associated content. Preserve its accessible name and the required root context.

HoverCardTrigger props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (15)
HoverCardTrigger inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLAnchorElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLAnchorElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLAnchorElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLAnchorElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLAnchorElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLAnchorElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
typestring | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
refReact.Ref<HTMLAnchorElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/hover-card.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Give sighted pointer and keyboard users a quick look at a profile, document or entity before they follow the link.
  • Help scanning dense content (mentions, references, linked records) where opening each destination would be slow.
  • Attach a preview to a link inside running text with asChild, keeping the existing anchor and its href.

When not to use

  • Information the user needs to complete a task; it would be invisible on touch screens and hard to reach with assistive technology.
  • Any control (buttons, form fields, links that are the only path somewhere); the card is not a keyboard-operated dialog.
  • A label or one-line description of a button or icon; use a tooltip.
  • Content the user opens on purpose to act on; use a popover.

Anatomy

HoverCard
Root. Holds open state (uncontrolled, or controlled with open and onOpenChange) and the openDelay and closeDelay timings.
HoverCardTrigger
An anchor by default; give it a real href, or compose an existing link with asChild.
HoverCardContent
Portaled preview panel positioned by side, align (default center) and sideOffset (default 6). Supplemental and not part of the Tab order.

Keyboard & interaction

  • The card opens after openDelay when a mouse pointer rests on the link, and when the link receives keyboard focus.
  • Moving the pointer from the link into the card keeps it open, so its text can be read and selected (WCAG 1.4.13 hoverable); it closes after closeDelay once the pointer leaves both.
  • Escape dismisses the card without moving focus away from the link (WCAG 1.4.13 dismissible); blur also closes it.
  • Tab moves from the link to the next element on the page, never into the card.
  • Activating the link navigates as usual; the card never intercepts the click.

Responsive behavior

  • Touch input does not open the card. On phones the link simply navigates, so the destination must contain everything the card previews.
  • Keep the card narrow enough for a 320px viewport (the default is w-64, 256px) and let long names wrap (WCAG 1.4.10).
  • Collision handling flips or shifts the card near viewport edges; do not design content that only makes sense on one side.
  • Inline links in text are exempt from the 24px target minimum, but links in lists or toolbars should still meet WCAG 2.5.8.

Content guidelines

  • Lead with the identity the link points to (name, title) followed by one or two lines of context.
  • Keep it short enough to read at a glance; a card that needs scrolling is the destination page, not a preview.
  • Write the link text so it makes sense without the card ('Ada Lovelace's profile', '@ada'), never 'hover here'.
  • Do not repeat the link text as the only content of the card; it adds nothing for anyone.

Alternatives

  • Tooltip — A short text description of a control, shown on hover and focus.
  • Popover — Interactive content the user opens with a click or key press and can Tab into.
  • Dialog — Full details that need focus, a title and actions.

Resources