Skip to content

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

Free

Product Preview Hover Card for React

Wireless Headphones Pro opens a card with $299, a struck-through $349, a description, a 4.8 rating, and In Stock.

The link is the product name. The card shows a package icon, $299 beside a struck-through $349, a short description, 4.8 from 2,431 reviews, and In Stock.

Reach for it in a cart or a recommendation list when leaving the page is too much. A Popover is the tap-friendly version. In React, Base UI does not look up the product. The copy is in the demo.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Hover Card anatomy: trigger, positioner, arrow, content

Usage

<HoverCard>
  <HoverCardTrigger
    className="font-medium text-sm underline underline-offset-4"
    closeDelay={100}
    delay={10}
    href="#"
  >
    Wireless Headphones Pro
  </HoverCardTrigger>
  <HoverCardContent className="w-80 max-w-full">
    <div className="flex flex-col gap-3">
      <div className="flex gap-3">
        <div className="flex size-16 shrink-0 items-center justify-center rounded-md bg-muted">
          <PackageIcon
            aria-hidden="true"
            className="size-8 text-muted-foreground"
          />
        </div>
        <div className="flex flex-1 flex-col gap-1">
          <h4 className="font-semibold text-sm">Wireless Headphones Pro</h4>
          <div className="flex items-center gap-2">
            <span className="font-bold text-lg">$299</span>
            <span className="text-muted-foreground text-sm line-through">
              $349
            </span>
          </div>
        </div>
      </div>
      <p className="text-muted-foreground text-sm">
        Premium wireless headphones with active noise cancellation, 30-hour
        battery life, and studio-quality sound.
{/* The rest of the file is under Installation. */}

FAQ

What is in the card?

A package icon in a muted square, the name, $299 beside $349 struck through, the description, a star with 4.8 (2,431 reviews) and In Stock.

How is the product link made the trigger?

HoverCardTrigger renders an anchor itself, so the product link is the trigger with href and its classes set on it.

How are the rating and the stock colored?

The star is filled with the warning token and In Stock uses text-success, so both follow the theme.

How wide is the card?

w-80 on the card, for the extra content. The class is on HoverCardContent. max-w-full keeps it inside narrow screens.

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. The demo sets delay 10 and closeDelay 100 on HoverCardTrigger. side and align on HoverCardContent place it.

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

Sets closeDelay={100}, delay={10} and href="#". The rest is on the Hover Card page.