Veil UI
Components

Hover Card

A preview card shown while hovering or focusing a trigger.

Installation

$ npx veil-ui@latest add hover-card

Usage

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

<HoverCard>
  <HoverCardTrigger asChild>
    <a href="#">@veil</a>
  </HoverCardTrigger>
  <HoverCardContent aria-label="Profile">
    Preview content
  </HoverCardContent>
</HoverCard>;

Examples

Basic

Profile

API reference

  • HoverCard opens on hover and on keyboard focus with configurable open and close delays.
  • HoverCardContent portals with role="dialog", w-64 width and configurable align / sideOffset.
  • Give the content an aria-label or a heading so it has an accessible name.

Accessibility

  • The content is a labelled dialog and stays open while the pointer is over it.
  • Keyboard focus on the trigger opens it, so it is not hover-only.
  • Content should be preview-oriented, not contain critical actions.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add hover-card --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { HoverCardContent, HoverCardPortal } from "reka-ui";

import { cn } from "@/lib/utils";

const props = withDefaults(
  defineProps<{
    class?: string;
    align?: "start" | "center" | "end";
    sideOffset?: number;
  }>(),
  { align: "center", sideOffset: 4 },
);
</script>

<template>
  <HoverCardPortal>
    <HoverCardContent
      data-slot="hover-card-content"
      role="dialog"
      :align="align"
      :side-offset="sideOffset"
      :class="
        cn(
          'z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none',
          'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=bottom]:slide-out-to-top-2 data-[side=top]:slide-out-to-bottom-2 data-[side=left]:slide-out-to-right-2 data-[side=right]:slide-out-to-left-2 origin-[var(--reka-popper-transform-origin)]',
          props.class,
        )
      "
    >
      <slot />
    </HoverCardContent>
  </HoverCardPortal>
</template>

On this page