A preview card that opens when a link is hovered or focused, for content sighted users can glance at.
Install
Add it to your project
Run this in a project set up for shadcn/ui. It writes the files and installs the npm packages.
First time: connect the Infinity UI registry
- Create a personal token on your Tokens page.
- Put it in
.env.localasINFINITYUI_TOKEN. - Add the registry to
components.json:
{
"registries": {
"@infinityui": {
"url": "https://infinityui.io/r/{name}.json",
"headers": {
"Authorization": "Bearer ${INFINITYUI_TOKEN}"
}
}
}
}Using Claude Code, Codex, Cursor, Lovable or v0? See CLI & MCP for a setup prompt.
npm packages it adds
- cn
- @base-ui/react
Code
"use client"
import * as React from "react"
import { IconMapPin } from "@tabler/icons-react"
import { cn } from "cn"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import {
createHoverCardHandle,
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card"
type Person = {
handle: string
name: string
initials: string
bio: string
location: string
}
const people: Record<string, Person> = {
mira: {
handle: "mira",
name: "Mira Okafor",
initials: "MO",
bio: "Design engineer. Obsessed with easing curves.",
location: "Lagos",
},
jun: {
handle: "jun",
name: "Jun Park",
initials: "JP",
bio: "Maintains the motion tokens and keeps the docs honest about what ships.",
location: "Seoul",
},
sol: {
handle: "sol",
name: "Sol Ferreira",
initials: "SF",
bio: "Accessibility.",
location: "Lisbon",
},
}
const profile = createHoverCardHandle<Person>()
function MentionLink({ className, ...props }: React.ComponentProps<"a">) {
return (
<a
className={cn(
"font-medium text-foreground underline decoration-border underline-offset-4 hover:decoration-foreground",
className
)}
{...props}
/>
)
}
function Mention({ person }: { person: Person }) {
return (
<HoverCardTrigger
handle={profile}
payload={person}
href="#"
delay={250}
render={<MentionLink />}
>
@{person.handle}
</HoverCardTrigger>
)
}
export function HoverCardDemo() {
return (
<>
<p className="max-w-sm text-center text-sm/relaxed text-muted-foreground">
Shipped by <Mention person={people.mira} />, reviewed by{" "}
<Mention person={people.jun} /> and tested with a screen reader by{" "}
<Mention person={people.sol} />.
</p>
<HoverCard handle={profile}>
{({ payload }) => (
<HoverCardContent arrow>
{payload && (
<div className="flex gap-3">
<Avatar>
<AvatarFallback>{payload.initials}</AvatarFallback>
</Avatar>
<div className="flex min-w-0 flex-col gap-1">
<p className="font-medium">{payload.name}</p>
<p className="text-muted-foreground">{payload.bio}</p>
<p className="flex items-center gap-1 pt-1 text-xs text-muted-foreground">
<IconMapPin className="size-3.5" aria-hidden="true" />
{payload.location}
</p>
</div>
</div>
)}
</HoverCardContent>
)}
</HoverCard>
</>
)
}
































