Active development has been paused. Read the announcement.

Tooltip

A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.

<script lang="ts">
	import { Tooltip } from 'radix-svelte';
	import type { ResolvedProps } from 'radix-svelte/internal/helpers';
	// These are internal icons, but they're not exported from the package.
	// Use your own icons instead.
	import Plus from '~icons/lucide/plus';

	let providerDelayDuration: number = 700;
	let providerSkipDelayDuration: number = 300;
	let providerDisableHoverableContent: boolean;
	let rootOpen: boolean;
	let rootDelayDuration: number = 700;
	let rootDisableHoverableContent: boolean;
	let portalContainer: HTMLElement | string;
	let contentSide = "top";
	let contentSideOffset: number;
	let contentAlign = "center";
	let contentAlignOffset: number;
	let contentArrowPadding: number;
	let contentCollisionPadding: number;
	let contentSticky = "partial";
	let contentHideWhenDetached: boolean;
	let contentAvoidCollisions: boolean = true;
	let arrowWidth: number = 10;
	let arrowHeight: number = 5;
</script>

<Tooltip.Provider
	delayDuration={providerDelayDuration}
	skipDelayDuration={providerSkipDelayDuration}
	disableHoverableContent={providerDisableHoverableContent}
>
	<Tooltip.Root
		bind:open={rootOpen}
		delayDuration={rootDelayDuration}
		disableHoverableContent={rootDisableHoverableContent}
	>
		<Tooltip.Trigger
			class="hover:opacity/75 inline-flex h-8 w-8 items-center justify-center rounded-full bg-white
			text-vermilion-500 shadow-sm outline-none focus:ring focus:ring-black"
			aria-label="Add to library"
		>
			<Plus />
		</Tooltip.Trigger>
		<Tooltip.Portal>
			<Tooltip.Content
				side={contentSide}
				sideOffset={contentSideOffset}
				align={contentAlign}
				alignOffset={contentAlignOffset}
				arrowPadding={contentArrowPadding}
				collisionPadding={contentCollisionPadding}
				sticky={contentSticky}
				hideWhenDetached={contentHideWhenDetached}
				avoidCollisions={contentAvoidCollisions}
				class="select-none rounded-md
				bg-white px-4
				py-2 leading-none text-vermilion-500 shadow-md will-change-[transform,opacity] data-[state=delayed-open]:data-[side=bottom]:animate-slideUpAndFade data-[state=delayed-open]:data-[side=left]:animate-slideRightAndFade data-[state=delayed-open]:data-[side=right]:animate-slideLeftAndFade 
				data-[state=delayed-open]:data-[side=top]:animate-slideDownAndFade"
			>
				Add to library

				<Tooltip.Arrow
					width={arrowWidth}
					height={arrowHeight}
					class="fill-white"
				/>
			</Tooltip.Content>
		</Tooltip.Portal>
	</Tooltip.Root>
</Tooltip.Provider>

API Reference

Provider

Wraps your app to provide global functionality to your tooltips.

Props
delayDuration
number
skipDelayDuration
number
disableHoverableContent
boolean

Root

Contains all the parts of a tooltip.

Props
open
boolean
delayDuration
number
disableHoverableContent
boolean

Trigger

The button that toggles the tooltip. By default, the Tooltip.Content will position itself against the trigger.

Props

No Props


Data Attributes
data-state
closed | delayed-open | instant-open

Portal

When used, portals the content part into the body.

Props
container
HTMLElement | string
N/A

Content

The component that pops out when the tooltip is open.

Props
side
enum
sideOffset
number
align
enum
alignOffset
number
arrowPadding
number
collisionPadding
number
sticky
enum
hideWhenDetached
boolean
avoidCollisions
boolean

Data Attributes
data-side
top | right | bottom | left
data-align
start | center | end

Arrow

An optional arrow element to render alongside the tooltip. This can be used to help visually link the trigger with the Tooltip.Content. Must be rendered inside Tooltip.Content.

Props
width
number
height
number
Inspired by Radix UI
Not affiliated with Radix UI or WorkOS.