Data display

Hover Card

A preview of a link's destination, shown while the link is hovered or focused.

Class nameTypeDescription
hover-cardplf:hover-cardComponentWraps the link and the preview
hover-card-triggerplf:hover-card-triggerPartThe link
hover-card-contentplf:hover-card-contentPartThe floating preview
hover-card-bodyplf:hover-card-bodyPartPlaces media beside the details
hover-card-mediaplf:hover-card-mediaPartA square for an icon or image
hover-card-detailsplf:hover-card-detailsPartThe text column
hover-card-titleplf:hover-card-titlePartThe preview's title
hover-card-descriptionplf:hover-card-descriptionPartMuted text under the title
hover-card-metaplf:hover-card-metaPartA small muted line, with an icon
hover-card-iconplf:hover-card-iconPartAn SVG icon; an icon class there doesn't need it

Default

The preview is hidden from assistive technologies and cannot hold links or controls, so the link’s destination must show everything it does.

@pelatform
Design guide
Top
Right
Bottom
Left
Bottom start
Bottom end

JavaScript

Hover Card needs JavaScript to show previews; without it, the link works as usual. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<link rel="stylesheet" href="icons/icons.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<link rel="stylesheet" href="icons/icons.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-hover-card Marks the wrapper
data-plf-hover-card-trigger Optional: marks the native <a href>, otherwise the wrapper’s direct child without hidden; touch follows it without a preview, and aria-disabled="true" turns the preview off
data-plf-hover-card-content Optional: marks the preview, otherwise the wrapper’s direct child with hidden; text and no interactive content
data-plf-open-delay Milliseconds of hover before opening, from 0 to 60000; 300 by default
data-plf-close-delay Milliseconds before closing once the pointer leaves, from 0 to 60000; 150 by default
data-plf-placement top, right, bottom (default) or left; flips to the opposite side when that has more room, and a left or right panel that fits on neither side opens below or above
data-plf-align start, center (default) or end; start and end follow the text direction
data-plf-side Set by the script on the open preview to the side it opened on
Method Behavior
PLF.HoverCard.getOrCreateInstance(element, options) Returns the instance, creating it for valid markup; options may set openDelay and closeDelay
PLF.HoverCard.getInstance(element) Returns the instance or null
instance.open() Opens at once; returns false when already open, canceled, dismissed or the link is unavailable
instance.close() Closes and cancels a pending open; returns false when nothing was open or the close was canceled
instance.getState() Returns {open, openDelay, closeDelay}
instance.destroy() Closes without events, cancels timers and removes listeners
Event When
plf:hover-card:before-open Before opening; cancelable
plf:hover-card:open After opening
plf:hover-card:before-close Before closing; cancelable
plf:hover-card:close After closing

Each event’s detail:

Property Value
instance The Hover Card instance
reason api, trigger, keyboard, or pointer for a press outside
trigger The link, or null from a method, Escape or a press outside
Key Action
Tab, Shift+Tab Focusing the link opens the preview; leaving it closes the preview
Escape Closes the preview; focus stays on the link
Enter Follows the link

React

HoverCard from @pelatform/react renders this wrapper around its link and preview, which opens on hover and focus as the script’s does; it keeps its own state, or the application sets it with open.

Prop Values Default
placement top, right, bottom, left bottom
align start, center, end center
openDelay Milliseconds of hover before opening 300
closeDelay Milliseconds before closing once the pointer and the focus leave 150
open true or false, which the application changes in onOpenChange Its own state
defaultOpen true starts open when the application does not set open false
onOpenChange (open, reason), called when the preview opens or closes: trigger (the pointer or a click on the link), keyboard (the focus or Escape) or pointer (a press outside) None

The parts:

Part Element
HoverCardTrigger An a with hover-card-trigger, which takes its href
HoverCardContent A div with hover-card-content and aria-hidden="true"
HoverCardBody A div with hover-card-body
HoverCardMedia A span with hover-card-media, in which an Icon needs no class
HoverCardDetails A div with hover-card-details
HoverCardTitle A p with hover-card-title
HoverCardDescription A p with hover-card-description
HoverCardMeta A p with hover-card-meta, in which an Icon needs no class

Other props are the element’s own, className and ref included.

Variable Default
--plf-hover-card-width 20rem, capped by the viewport
--plf-hover-card-padding --plf-space-4
--plf-hover-card-radius Large radius (8px)
--plf-hover-card-bg, --plf-hover-card-color Elevated surface and text
--plf-hover-card-border Subtle border
--plf-hover-card-shadow --plf-shadow-md
--plf-hover-card-trigger-color --plf-color-primary-text
--plf-hover-card-media-size 2.5rem
--plf-hover-card-icon-size --plf-control-icon-size

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons