A tiny text label beside an element, shown on hover and keyboard focus. Like the title attribute, but styled, positioned and animated. The browser does the work: no JavaScript opens it.
Browser Support
The interestfor attribute on a button or link opens the hint on hover, keyboard focus and long press, after a delay. Without it, plain CSS shows the hint on :hover and :focus-visible.
popover="hint" puts the label in the top layer, above everything, and closes on Escape without touching other popovers.
Places the hint beside the element and flips it to the other side when it would leave the screen. Without it the hint is placed with plain absolute positioning.
Preview
Hover an icon or Tab to it.
Installation
Usage
Wrap one element. Give an icon-only button its own aria-label: the hint describes the element, it does not name it.
import { Copy } from "lucide-react"
import { Hint } from "@/components/ui/hint"
<Hint content="Copy">
<button type="button" aria-label="Copy">
<Copy />
</button>
</Hint>Examples
Sides
side picks where the hint appears. It flips to the opposite side when there is no room.
<Hint content="Below" side="bottom">
<button type="button">bottom</button>
</Hint>Truncated text
A line cut with an ellipsis shows its full text in the hint. The trigger is a plain span, so the hint is driven by CSS hover here. Add tabIndex={0} if keyboard users need it too.
<Hint content={fileName} side="bottom">
<span className="block min-w-0 truncate">{fileName}</span>
</Hint>Hint and title
The title attribute is slow, cannot be styled, never shows on keyboard focus and does nothing on touch. Hint shows the same text consistently.
<Hint content="Copy the link">
<button type="button">Hint</button>
</Hint>
<button type="button" title="Copy the link">title attribute</button>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| content | string | - | Hint text. Plain text, nothing interactive. |
| children | ReactElement | - | One element that gets the hint. A button or link opens it natively, any other element uses CSS hover. |
| side | "top" | "bottom" | "left" | "right" | "top" | Which side of the element the hint appears on. |
| delay | number | 500 | Delay before the hint appears, in ms. A system tooltip waits about 500. |
| className | string | - | Extra classes for the hint bubble. |
Features
- Native first — interestfor and popover="hint" in the browser that has them: top layer, delay, Escape and cleanup come from the platform.
- No double tooltip — The title attribute is never added, so no browser shows two hints. Browsers without interestfor get the same bubble from CSS.
- Accessible — The element gets aria-describedby, the bubble has role="tooltip", Escape hides it in both modes and it never takes clicks.
- Touch — Browsers with interestfor open the hint on long press. In the CSS mode a tap shows nothing, because a sticky hover on touch is worse than no hint.