Tooltip

A tooltip displays a description of an element on hover or focus.

Example

Tone
Placement
Delay
Usage

Features

The HTML title attribute can be used to create a tooltip, but it cannot be styled. Custom styled tooltips can be hard to build in an accessible way. TooltipTrigger and Tooltip help build fully accessible tooltips that can be styled as needed.

  • Styleable – States for entry and exit animations are included for easy styling, and an optional arrow element can be rendered.
  • Accessible – The trigger element is automatically associated with the tooltip via aria-describedby. Tooltips are displayed when an element receives focus.
  • Hover behavior – Tooltips display after a global delay on hover of the first tooltip, with no delay on subsequent tooltips to avoid unintended flickering. Emulated hover events on touch devices are ignored.
  • Positioning – The tooltip is positioned relative to the trigger element, and automatically flips and adjusts to avoid overlapping with the edge of the browser window.

Installation

Install following dependencies:

npm install react-aria-components tw-animate-css tailwindcss-react-aria-components class-variance-authority lucide-react clsx tailwind-merge motion

Add cn helper using clsx and twMerge for conditional class merging in Tailwind components.

lib/utils.ts

Copy and paste the following code into your project.

components/ui/core/tooltip.tsx
npx @libravelui@latest add tooltip

Anatomy

[ANATOMY IMPORT HERE]
[ANATOMY CODE]

Another Examples

Placements

The list above shows the primary directions, but you can also use more specific placements like bottom left or top right. Here are all the available placement options:

Primary DirectionPlacement
bottombottom, bottom left, bottom right, bottom start, bottom end
toptop, top left, top right, top start, top end
leftleft, left top, left bottom
startstart, start top, start bottom
rightright, right top, right bottom
endend, end top, end bottom

Tones

Show different visual styles for tooltips, such as subtle, solid, or outlined, to match various interface themes and design preferences.

Without Arrow

Display tooltips without the directional arrow for a cleaner, more minimal appearance while still providing helpful context.

Delay

Control the display timing of tooltips by adding a delay before they appear or disappear, improving usability and preventing accidental triggers.

Props

Loading types…