Skip to main content

Starwind UI v3.0 is now available! Migration guide

Hover Card

Installation

Usage

---
import { Avatar, AvatarFallback, AvatarImage } from "@/components/starwind/avatar";
import { Button } from "@/components/starwind/button";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/starwind/hover-card";
---
<HoverCard>
<HoverCardTrigger asChild>
<Button variant="outline">@starwind</Button>
</HoverCardTrigger>
<HoverCardContent class="w-80" align="start">
<div class="flex justify-between gap-4">
<Avatar class="shrink-0">
<AvatarImage src="https://i.pravatar.cc/150?u=starwind" alt="Starwind UI" />
<AvatarFallback>SW</AvatarFallback>
</Avatar>
<div class="space-y-1">
<h4 class="text-sm font-semibold">Starwind UI</h4>
<p class="text-muted-foreground text-sm">
Accessible Astro components styled with Tailwind CSS.
</p>
<span class="text-muted-foreground block pt-2 text-xs">Built for Astro developers</span>
</div>
</div>
</HoverCardContent>
</HoverCard>

Composition

Use a trigger and content inside the root:

HoverCard
├── HoverCardTrigger
└── HoverCardContent

When to Use

Use Hover Card for optional context that appears when a trigger receives hover or keyboard focus.

Profile Preview

Use asChild on the trigger when you want to reuse an existing interactive component like Button.

Side and Alignment

Use side, align, and sideOffset on HoverCardContent to control placement.

Non-hoverable Content

By default, moving the pointer from trigger to content keeps the card open. Set disableHoverableContent to close immediately when leaving the trigger.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Hover Card Trigger

Inherits a attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Merges the component behavior and props into its child element.
Classification
Primitive override
Primitive prop
preview-card.Trigger.asChild
closeDelay number
Description
Sets the delay in milliseconds before closing.
Classification
Primitive override
Primitive prop
preview-card.Trigger.closeDelay
openDelay number
Description
Sets the delay in milliseconds before opening.
Classification
Primitive override
Primitive prop
preview-card.Trigger.openDelay

Hover Card Content

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
disablePortal boolean false
Description
Keeps the public Portal wrapper inline instead of moving it to a target.
Classification
Wrapper prop
portalContainer string
Description
Sets the CSS selector for the public Portal wrapper target.
Classification
Wrapper prop
positionerClass string
Description
Adds classes to the generated floating positioner element.
Classification
Wrapper prop
sideOffset number 4
Description
Sets the distance in pixels between floating content and its anchor.
Classification
Primitive override
Primitive prop
preview-card.Popup.sideOffset

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Hover Card.

Runtime API

Preview Card primitive
createPreviewCard from @starwind-ui/runtime/preview-card

Changelog

View version history v2.2.0 4 releases

v2.2.0

  • Added portalContainer and disablePortal to HoverCardContent for custom portal targets and inline rendering.

v2.1.0

  • Added positionerClass to HoverCardContent so the floating positioner can be styled directly.
  • Moved the default stacking level from the content to the positioner.

v2.0.2

  • Named the generated aggregate default export so React and Astro tooling can identify the installed component cleanly.

v2.0.0

  • Rebuilt Hover Card on Starwind Runtime for hover and focus state, floating placement, and dismissal.
  • See the Preview Card Primitive for the underlying unstyled anatomy and behavior API.