Tooltip
Displays informative text when users hover over or focus on an element
Import
import { Tooltip } from '@heroui/react';
Usage
"use client";
import {Button, Tooltip} from "@heroui/react";
import {Icon} from "@iconify/react";
export function TooltipBasic() {
return (
<div className="flex items-center gap-4">
<Tooltip delay={0}>
<Button variant="secondary">Hover me</Button>
<Tooltip.Content>
<p>This is a tooltip</p>
</Tooltip.Content>
</Tooltip>
<Tooltip delay={0}>
<Button isIconOnly variant="tertiary">
<Icon icon="gravity-ui:circle-info" />
</Button>
<Tooltip.Content>
<p>More information</p>
</Tooltip.Content>
</Tooltip>
</div>
);
}
Anatomy
Import all parts and piece them together.
import { Tooltip } from '@heroui/react';
export default () => (
<Tooltip>
<Tooltip.Trigger>
<button>Hover for tooltip</button>
</Tooltip.Trigger>
<Tooltip.Content>
<Tooltip.Arrow />
Helpful information about this element
</Tooltip.Content>
</Tooltip>
)
With Arrow
"use client";
import {Button, Tooltip} from "@heroui/react";
export function TooltipWithArrow() {
return (
<div className="flex items-center gap-4">
<Tooltip delay={0}>
<Button variant="secondary">With Arrow</Button>
<Tooltip.Content showArrow>
<Tooltip.Arrow />
<p>Tooltip with arrow indicator</p>
</Tooltip.Content>
</Tooltip>
<Tooltip delay={0}>
<Button variant="primary">Custom Offset</Button>
<Tooltip.Content showArrow offset={12}>
<Tooltip.Arrow />
<p>Custom offset from trigger</p>
</Tooltip.Content>
</Tooltip>
</div>
);
}
Placement
Hover buttons
"use client";
import {Button, Tooltip} from "@heroui/react";
export function TooltipPlacement() {
return (
<div className="grid grid-cols-3 gap-4">
<div />
<Tooltip delay={0}>
<Button className="w-full" variant="tertiary">
Top
</Button>
<Tooltip.Content showArrow placement="top">
<Tooltip.Arrow />
<p>Top placement</p>
</Tooltip.Content>
</Tooltip>
<div />
<Tooltip delay={0}>
<Button className="w-full" variant="tertiary">
Left
</Button>
<Tooltip.Content showArrow placement="left">
<Tooltip.Arrow />
<p>Left placement</p>
</Tooltip.Content>
</Tooltip>
<div className="flex items-center justify-center">
<span className="text-muted text-sm">Hover buttons</span>
</div>
<Tooltip delay={0}>
<Button className="w-full" variant="tertiary">
Right
</Button>
<Tooltip.Content showArrow placement="right">
<Tooltip.Arrow />
<p>Right placement</p>
</Tooltip.Content>
</Tooltip>
<div />
<Tooltip delay={0}>
<Button className="w-full" variant="tertiary">
Bottom
</Button>
<Tooltip.Content showArrow placement="bottom">
<Tooltip.Arrow />
<p>Bottom placement</p>
</Tooltip.Content>
</Tooltip>
<div />
</div>
);
}
Custom Triggers
Active
"use client";
import {Avatar, Chip, Tooltip} from "@heroui/react";
import {Icon} from "@iconify/react";
export function TooltipCustomTrigger() {
return (
<div className="flex items-center gap-6">
<Tooltip delay={0}>
<Tooltip.Trigger aria-label="User avatar">
<Avatar>
<Avatar.Image
alt="John Doe"
src="https://img.heroui.chat/image/avatar?w=400&h=400&u=1"
/>
<Avatar.Fallback>JD</Avatar.Fallback>
</Avatar>
</Tooltip.Trigger>
<Tooltip.Content showArrow>
<Tooltip.Arrow />
<div className="flex flex-col gap-0 py-1">
<p className="font-semibold">Jane Doe</p>
<p className="text-muted text-xs">jane@example.com</p>
</div>
</Tooltip.Content>
</Tooltip>
<Tooltip delay={0}>
<Tooltip.Trigger aria-label="Status chip">
<Chip color="success">
<Icon icon="gravity-ui:circle-check-fill" width={12} />
Active
</Chip>
</Tooltip.Trigger>
<Tooltip.Content className="flex items-center gap-1.5">
<span className="relative flex size-2">
<span className="bg-success absolute inline-flex h-full w-full animate-ping rounded-full opacity-75" />
<span className="bg-success relative inline-flex size-2 rounded-full" />
</span>
<p>Jane is currently online</p>
</Tooltip.Content>
</Tooltip>
<Tooltip delay={0}>
<Tooltip.Trigger aria-label="Info icon">
<div className="bg-accent-soft rounded-full p-2">
<Icon className="text-accent" icon="gravity-ui:circle-question" />
</div>
</Tooltip.Trigger>
<Tooltip.Content showArrow>
<Tooltip.Arrow />
<div className="max-w-xs px-1 py-1.5">
<p className="mb-1 font-semibold">Help Information</p>
<p className="text-muted text-sm">
This is a helpful tooltip with more detailed information about this feature.
</p>
</div>
</Tooltip.Content>
</Tooltip>
</div>
);
}
Styling
Passing Tailwind CSS classes
import {Tooltip, Button} from '@heroui/react';
function CustomTooltip() {
return (
<Tooltip>
<Button>Hover me</Button>
<Tooltip.Content className="bg-accent text-accent-foreground">
<p>Custom styled tooltip</p>
</Tooltip.Content>
</Tooltip>
);
}
Customizing the component classes
To customize the Tooltip component classes, you can use the @layer components
directive.
Learn more.
@layer components {
.tooltip {
@apply rounded-xl shadow-lg;
}
.tooltip__trigger {
@apply cursor-help;
}
}
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
CSS Classes
The Tooltip component uses these CSS classes (View source styles):
Base Classes
.tooltip
- Base tooltip styles with animations.tooltip__trigger
- Trigger element styles
Interactive States
The component supports animation states:
- Entering:
[data-entering]
- Applied during tooltip appearance - Exiting:
[data-exiting]
- Applied during tooltip disappearance - Placement:
[data-placement="*"]
- Applied based on tooltip position
API Reference
Tooltip Props
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | - | Trigger element and content |
delay | number | 700 | Delay in milliseconds before showing tooltip |
closeDelay | number | 0 | Delay in milliseconds before hiding tooltip |
trigger | "hover" | "focus" | "hover" | How the tooltip is triggered |
isDisabled | boolean | false | Whether the tooltip is disabled |
Tooltip.Content Props
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | - | Content to display in the tooltip |
showArrow | boolean | false | Whether to show the arrow indicator |
offset | number | 3 (7 with arrow) | Distance from the trigger element |
placement | "top" | "bottom" | "left" | "right" (and variants) | "top" | Placement of the tooltip |
className | string | - | Additional CSS classes |
Tooltip.Trigger Props
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | - | Element that triggers the tooltip |
className | string | - | Additional CSS classes |
Tooltip.Arrow Props
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | - | Custom arrow element |
className | string | - | Additional CSS classes |