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.jsonReviewed by @mira.designs, approved yesterday.
HoverCardHoverCardContentHoverCardTriggerLinkPreviewProfilePreview- +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.
import { Badge } from "@/components/sheenui/badge/badge";
import { HoverCard, HoverCardContent, HoverCardTrigger, ProfilePreview } from "@/components/sheenui/hover-card/hover-card";
// Package build (after the first npm release, or a packed tarball): import { Badge, HoverCard, HoverCardContent, HoverCardTrigger, ProfilePreview } from "@sheenui/theme";
// This example also uses badge: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/badge.json
export function Example() {
return (
<HoverCard>
<HoverCardTrigger href="https://example.com/ada-lovelace">@ada-lovelace</HoverCardTrigger>
<HoverCardContent>
<ProfilePreview
name="Ada Lovelace"
handle="ada-lovelace"
status="online"
badge={<Badge tone="accent">Maintainer</Badge>}
bio="Builds SheenUI. Likes glass, springs and contrast ratios above 4.5."
stats={[{ label: "followers", value: 12400 }, { label: "following", value: 183 }]}
joined="2019-03-14"
/>
</HoverCardContent>
</HoverCard>
);
}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.tslib/{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
Link preview
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.
import { HoverCard, HoverCardContent, HoverCardTrigger, LinkPreview } from "@/components/sheenui/hover-card/hover-card";
// Package build (after the first npm release, or a packed tarball): import { HoverCard, HoverCardContent, HoverCardTrigger, LinkPreview } from "@sheenui/theme";
export function Example() {
// Any image URL or data: URI works; 1.91 : 1 is the usual social-card shape.
const springOgImage = "https://example.com/og/motion.png";
const springIcon = "https://motion.dev/favicon.ico";
return (
<>
<HoverCard>
<HoverCardTrigger href="https://motion.dev" target="_blank" rel="noopener">Motion</HoverCardTrigger>
<HoverCardContent padded={false}>
<LinkPreview
url="https://motion.dev"
siteName="Motion"
title="Motion – A modern animation library for JavaScript and React"
description="Springs, gestures, layout animations and scroll effects."
image={springOgImage}
imageAlt="A spring curve that overshoots once, then settles on its target."
favicon={springIcon}
/>
</HoverCardContent>
</HoverCard>
{/* No image: the card shows a gradient with the site's initial. */}
<LinkPreview url="https://tailwindcss.com" siteName="Tailwind CSS" title="Tailwind CSS" description="A utility-first CSS framework." />
</>
);
}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.
import { Avatar } from "@/components/sheenui/avatar/avatar";
import { createHoverCardHandle, HoverCard, HoverCardContent, HoverCardTrigger, ProfilePreview } from "@/components/sheenui/hover-card/hover-card";
// Package build (after the first npm release, or a packed tarball): import { Avatar, createHoverCardHandle, HoverCard, HoverCardContent, HoverCardTrigger, ProfilePreview } from "@sheenui/theme";
type Person = { name: string; handle: string; href: string; bio: string };
const team: Person[] = [
{ name: "Asha Verma", handle: "@asha", href: "https://example.com/asha", bio: "Design systems." },
{ name: "Ravi Kumar", handle: "@ravi", href: "https://example.com/ravi", bio: "Frontend platform." },
{ name: "Meera Iyer", handle: "@meera", href: "https://example.com/meera", bio: "Accessibility." },
];
export function Example() {
const teamCard = createHoverCardHandle<Person>();
return (
<>
<div className="flex -space-x-2.5 any-pointer-coarse:space-x-1">
{team.map((person) => (
<HoverCardTrigger key={person.handle} handle={teamCard} payload={person} href={person.href} target="_blank" rel="noopener" variant="plain">
<Avatar name={person.name} />
</HoverCardTrigger>
))}
</div>
<HoverCard handle={teamCard}>
{({ payload }) => payload && (
<HoverCardContent>
<ProfilePreview {...payload} />
</HoverCardContent>
)}
</HoverCard>
</>
);
}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.
import { HoverCard, HoverCardContent, HoverCardTrigger, LinkPreview } from "@/components/sheenui/hover-card/hover-card";
// Package build (after the first npm release, or a packed tarball): import { HoverCard, HoverCardContent, HoverCardTrigger, LinkPreview } from "@sheenui/theme";
export function Example() {
return (
<HoverCard>
<HoverCardTrigger href="https://base-ui.com" target="_blank" rel="noopener" delay={500} closeDelay={250}>
Base UI
</HoverCardTrigger>
<HoverCardContent side="top" align="center" sideOffset={10} padded={false}>
<LinkPreview url="https://base-ui.com" siteName="Base UI" title="Base UI" description="Unstyled, accessible React components." />
</HoverCardContent>
</HoverCard>
);
}HoverCard
HoverCardTrigger / HoverCardContent
Content presets
LinkPreview props
ProfilePreview props
Keyboard
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
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .