Skip to content

React Hover Card

A glass React hover card that previews what is behind a link, opening on hover or keyboard focus after a short delay.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/hover-card.json

Reviewed by @mira.designs, approved yesterday.

  • HoverCard
  • HoverCardContent
  • HoverCardTrigger
  • LinkPreview
  • ProfilePreview
  • +4 more
  • +1 more

Profile preview

Hover or Tab to a mention. ProfilePreview formats numbers and the join date for the locale.

SheenUI is built by @jonasweber, with design reviews from @mira.designs and accessibility testing by @samr.

Files to copy

6 folders · 7 files · 3 packages
From theme/src/
  • components/hover-card/
  • components/avatar/
  • hooks/{use-media-query.ts, use-preferences.ts}
  • motion/light-follower.ts
  • lib/{cn.ts, initials.ts, popup-a11y.ts, popup-motion.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/hover-card.jsonRegistry item: hover-card. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/badge/
  • lib/warn-once.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/badge.json
Packages
pnpm add @base-ui/react clsx tailwind-merge

Image, site, title and description. Motion's card has an image (it fades in once loaded) and an image favicon; Base UI and Tailwind CSS have none, so a soft gradient with the site's initial keeps the card's shape. A broken image falls back to the same initial.

Overlays are built on Base UI, animated with Motion and styled with Tailwind CSS.

One card, many triggers

A handle links one HoverCard to triggers anywhere; each passes its own payload. Moving between avatars swaps the content without closing.

4 people on this project

Placement and delay

side flips to the other side when there is no room. delay is how long the pointer must rest on the link; closeDelay gives it time to reach the card.

HoverCard

PropTypeDefaultDescription
open / defaultOpen / onOpenChangeboolean / boolean / (open, details) => voidfalseControlled or uncontrolled (Base UI Preview Card).
handleHandle<Payload>NoneFrom createHoverCardHandle(): share one card between detached triggers.
childrenReactNode | ({ payload }) => ReactNodeNoneThe content; a function receives the active trigger's payload.
...propsBase UI propsNoneThe rest is passed to the underlying Base UI part (for example onOpenChangeComplete, actionsRef, triggerId, defaultTriggerId).

HoverCardTrigger / HoverCardContent

PropTypeDefaultDescription
delaynumber500How long to wait before the preview card opens. Specified in milliseconds.
closeDelaynumber250How long to wait before closing the preview card. Specified in milliseconds.
variant"link" | "plain""link""link" (default): accent underlined text for links in a sentence. "plain": only the focus ring (avatars, chips).
childrenReactNodeNoneThe card's content: your own markup, ProfilePreview or LinkPreview.
side"top" | "bottom" | "left" | "right""bottom"Preferred side of the trigger; it flips when there is no room.
align"center" | "end" | "start""center"Sets the alignment along that side.
sideOffsetnumber10Gap between the trigger and the card, in px.
paddedbooleantruePad the content (1rem). Turn off for edge-to-edge content such as LinkPreview's image.
touchHintReactNode"Tap the link again to open it."Shown under the content when a tap opened the card, so touch users know how to follow the link. Pass null to hide it (e.g. when the trigger is not a link).
containerHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null<body>Where to portal the card (defaults to <body>).
Trigger hrefstringNoneIt renders an <a>: the link stays the one accessible element.
Trigger payload / handlePayload / HandleNoneFor triggers outside <HoverCard>.

Content presets

PropTypeDefaultDescription
ProfilePreview{ name, handle?, avatarSrc?, status?, badge?, bio?, stats?, joined?, joinedLabel?, locale?, cover? }NoneProfile layout. stats values are shortened (12 400 → 12.4K); joined is formatted with Intl (a date-only string like "2021-08-01" is read as a local date).
LinkPreview{ url, title, description?, image?, imageAlt?, siteName?, favicon? }NoneLink card. Use with padded={false} on the content. The image fades in once loaded (again when image changes); without an image, or if it fails, the site's initial is shown.

LinkPreview props

PropTypeDefaultDescription
url (required)stringNoneThe page's address; its host name is shown under the title.
title (required)ReactNodeNoneShows the page's title as the card heading.
descriptionReactNodeNoneShows one or two lines about the page.
imagestringNoneSets the preview image (1.91 : 1, the usual social-card shape).
imageAltstring""Sets the alt text for the image.
siteNameReactNodeNoneShown instead of the host name, e.g. "GitHub".
faviconReactNodethe site's first letterSmall site icon: an image URL or your own element.
classNamestringNoneAdds extra classes to the card content.

ProfilePreview props

PropTypeDefaultDescription
name (required)stringNoneShows the person's name as the card heading.
handlestringNoneSets the username, shown as "@handle".
avatarSrcstringNoneAvatar image URL; without it the avatar shows initials.
status"online" | "away" | "offline"NoneShows the presence dot on the avatar ("online", "away", ...).
badgeReactNodeNoneSmall element next to the name, e.g. <Badge tone="accent">Pro</Badge>.
bioReactNodeNoneShows a line or two about the person.
statsProfilePreviewStat[]NoneNumbers are shortened for the locale (12 400 → "12.4K").
joinedstring | number | DateNoneJoin date; formatted with Intl for locale.
joinedLabel((formattedDate: string) => ReactNode)(date) => `Joined ${date}`Wording around the formatted join date (i18n).
localestringthe browser'sLocale for numbers and dates (defaults to the browser's).
coverbooleantrueDraws a decorative gradient band behind the avatar.
classNamestringNoneAdds extra classes to the card content.

Keyboard

KeysAction
Tab/Shift + TabFocusing the link opens the card after the delay.
EnterFollow the link.
EscapeClose the card.

Accessibility

  • A hover card is an extra for links: it is not announced, so the link text must make sense alone and the card must not hold the only copy of anything.
  • On touch screens the first tap opens the card and a second tap follows the link.
  • Content inside is not reachable by Tab; use a Popover for interactive content.

All exports on this page

  • HoverCard — Hover card: a glass preview of what is behind a link (a profile, a page) shown on hover or keyboard focus.
  • HoverCardContent — The glass card, portalled to the end of the body and positioned next to the trigger.
  • HoverCardTrigger — The link that opens the card.
  • LinkPreview — Link card content: image, site, title and description.
  • ProfilePreview — Profile card content: avatar, name, handle, bio, stats and join date.
  • createHoverCardHandle — Connects one HoverCard to triggers rendered elsewhere; pass payload on each trigger.

When to use the hover card

  • Use it as a profile preview popover for @mentions in a comment thread, where hovering a username link shows a profile preview with avatar, bio, stats and join date after a short delay.
  • Use it for external links in documentation, with LinkPreview content showing the site, title, description and a 1.91 to 1 image so readers can judge a link before leaving.
  • Use it for a link in a table or feed where passing the pointer across should do nothing: the default delay is 500 milliseconds, with a closeDelay of 250, so quick passes stay quiet.
  • Skip it when the content is interactive or essential; the card is not reachable by Tab, so Popover fits buttons and forms, and Tooltip fits a short label for an icon.
  • Pair it with Avatar and Badge inside ProfilePreview, Link-styled triggers using variant="link", and the page the link opens, where the essential version of the information should live.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .