Components
Hover card
Hover or focus preview panel for profiles, links, and contextual details.
Shipped by @ada and the platform team.
Composition
Anatomy
- <HoverCard>
- <HoverCardTrigger />
- <HoverCardContent />
Anchored to an element
When the hover target is not a React element, such as a decoration inside a rich text editor, control open yourself and pass that element to HoverCardContent's anchor prop instead of rendering a trigger.
- <HoverCard>
- <HoverCardContent />
Installation
The Control UI source installs this component from src/registry/sources/control-ui/ui/hover-card.tsx.
npx shadcn@latest add https://control-ui.dev/r/hover-card.jsonDependencies
Surface variants
src/registry/sources/control-ui/surface-variants.ts
Support
Raw code
Primary installed source
"use client";
import { PreviewCard as PreviewCardPrimitive } from "@base-ui/react/preview-card";import type { ComponentProps, CSSProperties, ReactNode } from "react";import type { OpenChangeEventDetails } from "@/components/control-ui/control-props";import type { PopupKnobStyle } from "@/components/control-ui/knob-contracts/popup-knobs";import { cn } from "@/components/control-ui/lib/cn";import { skinScopeAttributes } from "@/components/control-ui/skin";import { useSkin } from "@/components/control-ui/skin-provider";
export type HoverCardProps = { children?: ReactNode; open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean, eventDetails: OpenChangeEventDetails) => void;};
export type HoverCardContentProps = Omit< ComponentProps<"div"> & { side?: ComponentProps<typeof PreviewCardPrimitive.Positioner>["side"]; align?: ComponentProps<typeof PreviewCardPrimitive.Positioner>["align"]; sideOffset?: number; /** Positions the card against this element instead of the trigger, for hover targets React does not render. */ anchor?: ComponentProps<typeof PreviewCardPrimitive.Positioner>["anchor"]; }, "style"> & { style?: CSSProperties & PopupKnobStyle };
export function HoverCard(props: HoverCardProps) { return <PreviewCardPrimitive.Root {...props} />;}
export function HoverCardTrigger({ className, ...props}: ComponentProps<typeof PreviewCardPrimitive.Trigger> & { style?: CSSProperties & PopupKnobStyle }) { return ( // No family here: a control passed as `render` keeps its own, which its recipe is keyed on. <PreviewCardPrimitive.Trigger data-control-ui="hover-card" data-popup-kind="hover-card" data-slot="trigger" className={className} {...props} /> );}
export function HoverCardContent({ className, children, side = "bottom", align = "center", sideOffset = 8, anchor, ...props}: HoverCardContentProps) { const skin = useSkin(); return ( <PreviewCardPrimitive.Portal> <PreviewCardPrimitive.Positioner data-control-ui="hover-card" data-popup-kind="hover-card" data-control-family="popup" data-slot="positioner" {...skinScopeAttributes(skin)} side={side} align={align} sideOffset={sideOffset} anchor={anchor} className="z-(--z-popup)" > <PreviewCardPrimitive.Popup data-control-ui="hover-card" data-popup-kind="hover-card" data-control-family="popup" data-slot="content" data-surface="floating" data-popup-part="surface" className={cn("w-64", className)} {...props} > {children} </PreviewCardPrimitive.Popup> </PreviewCardPrimitive.Positioner> </PreviewCardPrimitive.Portal> );}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-popup-title-foreground | <color> | var(--cui-popup-foreground) |
--cui-popup-title-font-size | <length-percentage> | var(--text-heading-3) |
--cui-popup-title-font-weight | <number> | var(--font-weight-semibold) |
--cui-popup-title-line-height | <number> | var(--text-heading-3--line-height) |
--cui-popup-title-letter-spacing | <length> | -0.025em |
--cui-popup-description-foreground | <color> | var(--muted-foreground) |
--cui-popup-description-font-size | <length-percentage> | var(--text-body) |
--cui-popup-close-inset | <length-percentage> | calc(var(--spacing) * 3) |
--cui-popup-item-inset | <length-percentage> | calc(var(--spacing) * 8) |
--cui-popup-label-padding-block | <length-percentage> | var(--cui-popup-item-padding-block) |
--cui-popup-label-padding-inline | <length-percentage> | var(--cui-popup-item-padding-inline) |
--cui-popup-label-font-size | <length-percentage> | var(--text-micro) |
--cui-popup-label-font-weight | <number> | var(--font-weight-medium) |
--cui-popup-label-letter-spacing | <length> | 0.08em |
--cui-popup-label-text-transform | none | uppercase | lowercase | capitalize | uppercase |
--cui-popup-separator-inset | <length-percentage> | calc(var(--popover-padding) * -1) |
--cui-popup-shortcut-font-size | <length-percentage> | var(--text-body) |
--cui-popup-shortcut-letter-spacing | <length> | 0.02em |
--cui-popup-separator-gap | <length-percentage> | calc(var(--spacing) * 1) |
--cui-popup-submenu-indicator-foreground | <color> | var(--cui-popup-item-foreground) |
--cui-popup-command-padding | <length-percentage> | 0px |
--cui-popup-command-heading-padding-block | <length-percentage> | calc(var(--spacing) * 1.5) |
--cui-popup-command-heading-padding-inline | <length-percentage> | calc(var(--spacing) * 2) |
--cui-popup-command-heading-font-size | <length-percentage> | var(--text-caption) |
--cui-popup-command-heading-letter-spacing | <length> | calc(var(--cui-popup-command-heading-font-size) * 0.08) |
--cui-popup-command-heading-text-transform | none | uppercase | lowercase | capitalize | uppercase |
--cui-popup-dialog-max-inline-size | <length-percentage> | 32rem |
--cui-popup-list-max-height | <length-percentage> | 20rem |
--cui-popup-item-description-foreground | <color> | var(--muted-foreground) |
--cui-popup-item-description-font-size | <length-percentage> | var(--text-label) |
--cui-popup-shortcut-foreground | <color> | var(--muted-foreground) |
--cui-popup-tooltip-arrow-radius | <length-percentage> | min(var(--radius-sm), 3px) |
--cui-popup-shortcut-highlight-foreground | <color> | var(--cui-popup-item-highlight-foreground) |
--cui-popup-submenu-indicator-highlight-foreground | <color> | var(--cui-popup-item-highlight-foreground) |
--cui-popup-status-success-foreground | <color> | var(--success-text) |
--cui-popup-status-warning-foreground | <color> | var(--warning-text) |
--cui-popup-status-info-foreground | <color> | var(--info-text) |
--cui-popup-status-error-foreground | <color> | var(--destructive) |
--cui-popup-radius | <length-percentage> | var(--radius-popover) |
--cui-popup-background | <color> | var(--popover) |
--cui-popup-foreground | <color> | var(--popover-foreground) |
--cui-popup-border-color | <color> | var(--control-rim) |
--cui-popup-border-width | <length> | var(--control-rim-width) |
--cui-popup-shadow | * | var(--shadow-pop) |
--cui-popup-backdrop-filter | * | blur(var(--backdrop-blur-popover)) |
--cui-popup-backdrop-background | <color> | oklch(from var(--foreground) l c h / var(--overlay-opacity)) |
--cui-popup-backdrop-blur | <length> | var(--backdrop-blur-overlay) |
--cui-popup-item-radius | <length-percentage> | var(--radius-popup-item-fit) |
--cui-popup-item-font-size | <length-percentage> | var(--text-body) |
--cui-popup-item-icon-size | <length-percentage> | 1rem |
--cui-popup-item-padding-block | <length-percentage> | calc(var(--spacing) * 1) |
--cui-popup-item-padding-inline | <length-percentage> | calc(var(--padding-x) * 0.5) |
--cui-popup-item-min-height | <length-percentage> | max(var(--target-min), var(--control-h-xs)) |
--cui-popup-item-highlight-shadow | * | none |
--cui-popup-item-foreground | <color> | var(--foreground) |
--cui-popup-item-highlight-background | <color> | var(--hover-fill) |
--cui-popup-item-highlight-foreground | <color> | var(--cui-popup-item-foreground) |
--cui-popup-item-highlight-muted-foreground | <color> | var(--muted-foreground) |
--cui-popup-item-disabled-opacity | <number> | var(--disabled-opacity) |
--cui-popup-separator-color | <color> | var(--cui-popup-border-color) |