Hover Card
A preview that opens when a pointer rests on a link, such as a person or a record.
When to use
- A preview of a linked person or record: a clinician's specialty and clinic, shown on their name.
When not to use
- Information users need: put it on the page, or on the page the link opens.
- A label for an icon button: use Tooltip.
- Content with buttons or fields: use Popover.
Install
npx shadcn@latest add @clinia/hover-cardAnatomy
Dr. Jane Cooper
JC
Dr. Jane CooperCardiology · Montreal clinic. On call until 6 p.m.
- 1Trigger, a real link
data-slot="hover-card-trigger"underline · decoration-accent - 2Card
data-slot="hover-card-content"bg-popover · w-72 · p-4 - 3Name
[data-part=name]font-medium - 4Detail
[data-part=detail]text-muted-foreground
Clinia rules
- The trigger is a real link to the full record. The card previews what's there.
- It opens after 600 ms and closes 300 ms after the pointer leaves. Change that with
delayandcloseDelayon the trigger. - Keep it to a few lines: a name, a role, one detail. It is
w-72by default.
Do and don't
JC
Dr. Jane CooperCardiology · Montreal clinic. On call until 6 p.m.
JC
Dr. Jane CooperCardiology · Montreal clinic. On call until 6 p.m.
Accessibility
Built in
- Opens when the link gets keyboard focus as well as on hover, and closes when focus or the pointer leaves.
- Waits 600 ms before opening, so a pointer passing over the link doesn't open it.
Your responsibility
- Hover cards only open on hover and focus, and touch screens can't hover. Never put the only copy of information, or any action, inside one.
- Only use it on a link whose destination holds the same information.
- Style the trigger as a link with the borderless focus ring:
focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2.
How to test
- Rest the pointer on the link: the card opens after a short delay.
- Press Tab to the link: the card opens, and Enter follows the link.
- With a screen reader, only the link is read. Check that the linked page has everything the card shows.
API
Every prop comes from Base UI Preview Card.