shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/radix/hover-card.jsonnpx shadcn@latest add https://kit.dev/r/radix/hover-card.jsonpnpm dlx shadcn@latest add https://kit.dev/r/radix/hover-card.jsonyarn shadcn@latest add https://kit.dev/r/radix/hover-card.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add radix-uinpm install radix-uipnpm add radix-uiyarn add radix-uiCopy and paste the following code into your project.
"use client";
import { HoverCard as HoverCardPrimitive } from "radix-ui";
import type React from "react";
import { cn } from "@/lib/utils";
export const HoverCard = (
props: React.ComponentProps<typeof HoverCardPrimitive.Root>
) => <HoverCardPrimitive.Root data-slot="hover-card" {...props} />;
export const HoverCardTrigger = (
props: React.ComponentProps<typeof HoverCardPrimitive.Trigger>
) => <HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />;
export const HoverCardContent = (
props: React.ComponentProps<typeof HoverCardPrimitive.Content>
) => {
const { className, align = "center", sideOffset = 4, ...rest } = props;Update the import paths to match your project setup.
Anatomy
HoverCardArrow
└── HoverCardArrowTip
HoverCardTrigger
HoverCardContent
└── HoverCardPositionerUsage
import { Button } from "@/components/ui/button";
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card";<HoverCard>
<HoverCardTrigger asChild>
<Button variant="link">Hover Here</Button>
</HoverCardTrigger>
<HoverCardContent className="flex w-64 flex-col gap-0.5">
<div className="font-semibold">@nextjs</div>
<div>The React Framework – created and maintained by @vercel.</div>
<div className="mt-1 text-muted-foreground text-xs">
Joined December 2021
</div>
</HoverCardContent>
</HoverCard>Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused item. |
Space | Activate the focused control. |
Demos
Sides
Position the hover card with Ark positioning.placement.
Rtl
Right-to-left hover card. See the RTL configuration guide for document direction.
API Reference
HoverCard
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodecloseDelay?numberopenDelay?numberAttributeType
HoverCardTrigger
button
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodecloseDelay?numberopenDelay?numberAttributeType
HoverCardContent
div
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodecloseDelay?numberopenDelay?numberAttributeType
CSS variableType
--radix-hover-card-content-transform-originstring