Hover Card
FreeNewA preview that opens when a link is hovered or focused, after a short wait so passing over it does not flash a card.
Installation
pnpm dlx shadcn@latest add @viewport/hover-card
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
import { CalendarDays, MapPin } from "lucide-react";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/viewport/hover-card";
function Person({ handle, name, role, place, joined, initials }: { handle: string; name: string; role: string; place: string; joined: string; initials: string }) {
return (
<HoverCard>
<HoverCardTrigger href={`#${handle}`} className="rounded-sm font-medium text-foreground underline decoration-border underline-offset-4 outline-none transition-colors hover:decoration-foreground focus-visible:ring-2 focus-visible:ring-ring">
@{handle}
</HoverCardTrigger>
<HoverCardContent>
<div className="flex items-start gap-3">
<span aria-hidden className="grid size-10 shrink-0 place-items-center rounded-full bg-foreground text-sm font-semibold text-background">
{initials}
</span>
<div className="min-w-0">
<p className="font-medium">{name}</p>
<p className="text-muted-foreground">{role}</p>
</div>
</div>
<div className="mt-3 flex flex-col gap-1.5 text-xs text-muted-foreground">
<span className="inline-flex items-center gap-1.5">
<MapPin className="size-3.5" aria-hidden />
{place}
</span>
<span className="inline-flex items-center gap-1.5">
<CalendarDays className="size-3.5" aria-hidden />
Joined {joined}
</span>
</div>
</HoverCardContent>
</HoverCard>
);
}
export default function HoverCardDemo() {
return (
<p className="max-w-sm text-pretty text-sm leading-relaxed text-muted-foreground">
The renewal was approved by <Person handle="mara" name="Mara Lindqvist" role="Head of Revenue" place="Stockholm, Sweden" joined="March 2023" initials="ML" /> and handed to{" "}
<Person handle="theo" name="Theo Okafor" role="Account Executive" place="Lagos, Nigeria" joined="January 2025" initials="TO" /> for the kickoff call on Thursday.
</p>
);
}Accessibility
- Opens on keyboard focus as well as hover.
- Supplementary only: the link still works without it, which is what touch users get.
- Stays open while the pointer moves into the card.
- No scale animation under reduced motion.