Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Document Preview Hover Card for Svelte

Project Proposal.pdf opens a card with a file icon, 2.4 MB, PDF Document, a short summary, and the last modified date.

UI library: Ark UI

The link reads Project Proposal.pdf. The card shows a file icon in the destructive color, 2.4 MB, PDF Document, a summary of the Q1 proposal, and Last modified: December 15, 2023.

Use it in a file list so people can confirm the document before opening it. If the card has to open on a tap, use a Popover. In Svelte, Ark UI opens the card after a short pause.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Hover Card anatomy: trigger, positioner, arrow, content

Usage

<HoverCard><HoverCardTrigger>{#snippet asChild(props)}<a {...props(/* <a> attributes; Ark types these as <button>'s */ { class: "flex items-center gap-2 font-medium text-sm underline underline-offset-4", href: "#" } as never)}><FileTextIcon aria-hidden="true" class="size-4" />Project Proposal.pdf</a>{/snippet}</HoverCardTrigger><HoverCardContent class="w-80"><div class="flex flex-col gap-3"><div class="flex items-start gap-3"><div class="flex size-10 shrink-0 items-center justify-center rounded-md bg-destructive/10"><FileTextIcon aria-hidden="true" class="size-5 text-destructive" /></div><div class="flex flex-1 flex-col gap-1"><h4 class="font-semibold text-sm">Project Proposal.pdf</h4><p class="text-muted-foreground text-xs">2.4 MB · PDF Document</p></div></div><p class="text-muted-foreground text-sm">Comprehensive project proposal including timeline, budget, and deliverables for Q1 2024.</p><p class="text-muted-foreground text-xs">Last modified: December 15, 2023</p></div></HoverCardContent></HoverCard>

FAQ

What is in the card?

A file icon on a bg-destructive/10 tile, the name, 2.4 MB · PDF Document, the summary and Last modified: December 15, 2023.

How is the file link made the trigger?

HoverCardTrigger renders the file link through its asChild snippet.

Why is the file icon red?

Red is the usual color for PDF files. The tile uses the destructive token, bg-destructive/10 with a text-destructive icon, so it follows the theme. Pick a token per file type.

How wide is the card?

w-80 on the card, for the extra content. The class is on HoverCardContent.

How do I change how fast the card opens and closes?

The card opens a moment after the pointer rests on the trigger and stays up long enough for the pointer to move into it. Both delays are in milliseconds. Set openDelay and closeDelay on HoverCard; they default to 10 and 100. positioning picks another side than the bottom.

Does the card open from the keyboard and on touch screens?

Focusing the link opens the card, moving focus away or pressing Escape closes it. Touch screens have no hover, so keep what matters reachable elsewhere, or use a Popover when the card has to open on a tap.

API Reference

Hover Card

No extra props in this demo. The rest is on the Hover Card page.