nook
Browse the docs

Components

Hover Card

Built on Base UI

A preview of what a link leads to, shown on hover or focus.

See the prompt

Reviewed by Maya Chen on Monday.

Installation

npx nook-ui@latest add hover-card

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Hover Card" component to this project, exactly as Nook ships it.

A preview of what a link leads to, shown on hover or focus.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add hover-card`. It writes `components/ui/hover-card.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/hover-card.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card";

export default function HoverCardDefault() {
  return (
    <p className="text-sm">
      Reviewed by{" "}
      <HoverCard>
        <HoverCardTrigger href="#maya">Maya Chen</HoverCardTrigger>
        <HoverCardContent>
          <div className="flex gap-3">
            <Avatar>
              <AvatarFallback>MC</AvatarFallback>
            </Avatar>
            <div className="grid gap-1">
              <p className="font-medium">Maya Chen</p>
              <p className="text-muted-foreground">Design lead. Owns the launch page and the brand refresh.</p>
              <p className="text-xs text-muted-foreground">Usually replies within a day</p>
            </div>
          </div>
        </HoverCardContent>
      </HoverCard>{" "}
      on Monday.
    </p>
  );
}
```

API
- `HoverCard, HoverCardTrigger`: The root and the link. `delay` and `closeDelay` on the trigger set the timing.
- `HoverCardContent`: The card.
  - `side` (`"top" | "right" | "bottom" | "left"`, default "bottom"): Preferred side.
  - `align` (`"start" | "center" | "end"`, default "start"): Alignment along that side.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The trigger is a link and works without the card. The card opens on hover and on keyboard focus, and is not shown to touch users, so never put anything in it that cannot be reached another way.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card";

export default function HoverCardDefault() {
  return (
    <p className="text-sm">
      Reviewed by{" "}
      <HoverCard>
        <HoverCardTrigger href="#maya">Maya Chen</HoverCardTrigger>
        <HoverCardContent>
          <div className="flex gap-3">
            <Avatar>
              <AvatarFallback>MC</AvatarFallback>
            </Avatar>
            <div className="grid gap-1">
              <p className="font-medium">Maya Chen</p>
              <p className="text-muted-foreground">Design lead. Owns the launch page and the brand refresh.</p>
              <p className="text-xs text-muted-foreground">Usually replies within a day</p>
            </div>
          </div>
        </HoverCardContent>
      </HoverCard>{" "}
      on Monday.
    </p>
  );
}

Examples

Project card

Built with nook/ui.

Link preview

Read our guide to planning a trip by train.

Open delay

Assigned to Kofi Mensah.

Props

HoverCard, HoverCardTrigger

The root and the link. `delay` and `closeDelay` on the trigger set the timing.

HoverCardContent

The card.

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Preferred side.
align"start" | "center" | "end""start"Alignment along that side.

Accessibility

The trigger is a link and works without the card. The card opens on hover and on keyboard focus, and is not shown to touch users, so never put anything in it that cannot be reached another way.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.