shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A hover card is a small preview that opens while the pointer rests on a link, such as the handle, bio and join date behind a username. It opens after a short delay you can tune and stays up while the pointer moves into it, so people can read the card and select its text.
For a few words on an icon button, use a Tooltip. When the panel has to open from a click or a tap, or holds controls people must reach, use a Popover.
Installation
Anatomy

Usage
<script setup lang="ts">
import { Button } from "@/components/ui/button"
import {
HoverCard, HoverCardContent, HoverCardTrigger,
} from "@/components/ui/hover-card"
</script>
<template>
<HoverCard>
<HoverCardTrigger>
<template #render="{ props }">
<Button v-bind="props" variant="link">Hover Here</Button>
</template>
</HoverCardTrigger>
<HoverCardContent class="flex w-64 flex-col gap-0.5">
<div class="font-semibold">@nextjs</div>
<div>The React Framework – created and maintained by @vercel.</div>
<div class="mt-1 text-muted-foreground text-xs">Joined December 2021</div>
</HoverCardContent>
</HoverCard>
</template>Accessibility
UI SDK gives the card no role and the trigger no ARIA that points to it, so a screen reader says nothing when the card opens. Keyboard focus on the trigger opens it after the delay, Tab then moves into the card when it holds a link or a button, and Escape closes it. Focus leaving both the trigger and the card closes it too. Treat the card as a preview for pointer users, and keep anything people need, such as the profile link, on the page itself.
- Tab
- Opens the hover card once keyboard focus reaches the trigger, after the delay. While the card is open, moves focus from the trigger to the first focusable element in the card.
- EscEscape
- If open, closes the hover card. From inside the card, focus goes back to the trigger.
Demos
Link preview
A link inside a sentence, this article, opens a card with the post's title, a one-line summary and its site. That is the hover card's main job: a preview for people with a pointer, while the link still goes where it says. The trigger is the link itself, an a with an href.
Sides
Four outline buttons, left, top, bottom and right, each open a card that says which side it took. placement in the positioning prop on HoverCard picks the side. Both delays are 100 milliseconds so you can sweep along the row. Pin a side when the card would otherwise cover the text someone is reading.
RTL
A product preview in Arabic, wireless headphones at $99.99, inside a Direction provider set to right to left. The hover card carries the direction of the place it is written to its portaled card, so the card reads right to left too. placement in the positioning prop only takes physical sides, so the second row maps the start of the line to right and its end to left.
FAQ
Should I use a Hover Card, a Tooltip or a Popover?
Use a Hover Card for a preview that takes more than a glance, such as a profile card behind a username or a summary behind a link to a document. It's extra context for pointer users, and the link itself still does the main job.
A Tooltip is a short label on an icon button, shown on hover or focus. A Popover opens on a click, works on touch screens and keyboards alike, and is the one to use when the panel holds buttons or fields.
Why does my Hover Card open slowly, or close before I can reach it?
Both are delays in milliseconds. This file sets openDelay to 10 and closeDelay to 100 on HoverCard, where UI SDK's own defaults are 600 and 300. UI SDK's delay on HoverCard sets the open delay too, and wins over openDelay.
A longer open delay stops cards from flashing as the pointer crosses a list of names. If the card closes as the pointer travels to it, raise the close delay or shrink the gap between the trigger and the card.
How do I control whether a Hover Card is open in Vue?
Bind a ref with v-model:open on HoverCard, which writes the next state back each time the card opens or closes.
Hover, focus and Escape still ask to change it, so keep the callback wired. Controlling it is useful for opening a card from a tour step, or for keeping it open while you style it.
How do I choose which side a Hover Card opens on?
Set placement in the positioning prop on HoverCard, such as top or right-start, with bottom as the default. gutter in the same object sets the gap between the trigger and the card. HoverCardContent also takes UI SDK's own side, align and sideOffset, which win over positioning, and its side takes inline-start and inline-end, which follow the card's reading direction.
The Sides demo shows all four. When there isn't room on the side you picked, the card flips to the opposite one.
How do I use a link or a button as the Hover Card trigger?
HoverCardTrigger renders an a already, so give it an href. For a Button or a router link, put it in the trigger's #render slot and bind the slot's props on it with v-bind="props", as the demos do.
Keep the trigger focusable, so keyboard users get the card on focus. The username or the document title makes a better trigger than an info icon, since the card previews what the link leads to, as in the Link preview demo.
Can keyboard and screen reader users reach the links inside a Hover Card?
With a keyboard, yes, but a screen reader isn't told. While the card is open, Tab from the trigger moves into it and Escape closes it again, yet UI SDK gives the trigger no ARIA that points to the card, so nothing is announced when it opens. Put every link and action in the card somewhere else on the page too, or use a Popover when the panel exists for its buttons.
Does a Hover Card work on a phone or a tablet?
Don't count on it. A touch screen has no hover, and UI SDK ignores touch pointers in its hover handling, so a tap goes through to the link or button and does what it would anyway. Keep anything a phone user needs out of the card, or open a Popover on a tap instead.
API Reference
HoverCard
open?boolean
Whether the card is open. Pass it to control the card. Two-way with v-model or v-model:open.
defaultOpen?boolean
Whether the card starts open, when uncontrolled.
- Default
false
closeDelay?number
Milliseconds before the card closes once the pointer leaves the trigger and the card. UI SDK's default: 300.
- Default
trigger.closeDelay
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
controller?PopupController<any, HoverCardOpenChangeReason, {}, string, HoverCardPayloadChangeReason>
Opens, closes and inspects the card from anywhere, and connects triggers outside it. Create one with createHoverCardController().
- Type
PopupController<any, HoverCardOpenChangeReason, {}, string, HoverCardPayloadChangeReason>
debug?boolean
Logs every state change with its reason to the console, in development builds.
delay?number
Milliseconds the pointer rests on the trigger, or keyboard focus stays on it, before the card opens. UI SDK's default: 600.
- Default
trigger.delay
disabled?boolean
Stops the card from opening. The trigger keeps working as a link.
- Default
false
@open-change(open: boolean, details: ChangeDetails<HoverCardOpenChangeReason>) → void
Runs when the card wants to open or close. details.reason says why, and details.cancel() stops it.
- Type
(open: boolean, details: ChangeDetails<HoverCardOpenChangeReason>) → void- Parameters
open– booleandetails– ChangeDetails<HoverCardOpenChangeReason>- Returns
void
@open-change-complete(open: boolean) → void
Runs once the card has finished opening or closing, after any animation.
- Parameters
open– boolean- Returns
void
@payload-change(payload: unknown, details: ChangeDetails<HoverCardPayloadChangeReason>) → void
Runs when the payload the content shows changes: a trigger with another payload opens the card, or takes the open card over, which fires no onOpenChange, and so does a controller's open({ payload }) on the open card. details.cancel() keeps the previous payload.
- Type
(payload: unknown, details: ChangeDetails<HoverCardPayloadChangeReason>) → void- Parameters
payload– unknowndetails– ChangeDetails<HoverCardPayloadChangeReason>- Returns
void
HoverCardTrigger
<a> data-slot="hover-card-trigger"
closeDelay?number
Milliseconds before the card closes once the pointer leaves it and the trigger.
controller?PopupController<any, HoverCardOpenChangeReason, {}, string, HoverCardPayloadChangeReason>
Connects a trigger outside the card, like every author link in a feed, to the card with this controller.
- Type
PopupController<any, HoverCardOpenChangeReason, {}, string, HoverCardPayloadChangeReason>
delay?number
Milliseconds the pointer rests on the trigger before the card opens.
payload?unknown
Data for the content to render when this trigger opens the card, like the profile it links to.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
data-closed?string
Present while the card is closed, including while it animates out.
data-open?string
Present while the card is open. On a trigger, while it's open from that trigger.
HoverCardContent
<div> data-slot="hover-card-content"
align?Align
How the popup lines up with the anchor along that side. start and end follow the reading direction. How the card lines up with the trigger along that side.
- Default
"center"
alignOffset?number
Shift along the anchor, in pixels. Shift along the trigger, in pixels.
- Default
0
anchor?string | Anchor | null
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.
- Type
string | Anchor | null
arrowPadding?number
Space to keep between the arrow and the popup's corners, in pixels.
- Default
6
collisionPadding?number
Space to keep from the viewport edges, in pixels.
- Default
8
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
keepMounted?boolean
Whether the card stays in the page, hidden, while closed. Its content keeps its state between opens.
- Default
false
side?HoverCardSide
The side of the trigger it opens on. It flips when there's no room, unless avoidCollisions is off.
- Default
"bottom"
sideOffset?number
Gap between the anchor and the popup, in pixels. Gap between the trigger and the card, in pixels.
- Default
4
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-align"start" | "center" | "end"
How the card lines up with its trigger.
- Type
"start" | "center" | "end"
data-closed?string
Present while the card is closed, including while it animates out.
data-ending-style?string
Present while the card animates out. Style the state you animate to.
data-open?string
Present while the card is open. On a trigger, while it's open from that trigger.
data-side"top" | "right" | "bottom" | "left"
Where the card ended up, after flipping away from edges. Set on the arrow too.
- Type
"top" | "right" | "bottom" | "left"
data-starting-style?string
Present for the first frame. Style the state you animate from.
--anchor-heightstring
Height of the anchor.
--anchor-widthstring
Width of the anchor, usually the trigger. Use it to match widths.
--arrow-offsetstring
Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.
--available-heightstring
Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins.
--available-widthstring
Space beside the popup, up to the viewport edge. Not inherited either.
--transform-originstring
Where the content scales from, on its trigger's side.











