Components

Tooltip component

Display elegant tooltips with kit:tooltip. Fine-tuned customization, accessibility and SEO-friendliness for your Svelte components The kit:tooltip component can be used to display a tooltip on hover, focus or via a controlled opening. It’s designed to provide a simple, accessible way of delivering contextual information to the user, without cluttering up the interface.

kit:tooltip can be used with simple text using the label prop, or with richer HTML content using the tooltip slot.

It is particularly useful for enhancing the user experience by explaining icons, specifying actions or providing secondary details.

tooltip.svelte
<script lang="ts">
	import { Info } from 'lucide-svelte';
</script>

<div style="display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap;">
	<kit:tooltip label="I'm a tooltip">
		<kit:btn>Hover me</kit:btn>
	</kit:tooltip>

	<kit:tooltip label="More information">
		<kit:icon><Info /></kit:icon>
	</kit:tooltip>
</div>

kit:tooltip wraps its children in a <span> that listens for mouseenter, mouseleave, focusin, and focusout. The tooltip appears after delayDuration milliseconds on hover (default 850ms), right away on focus, and is shown in the top layer next to its trigger. The pointer can move onto the tooltip without closing it, and Escape closes it, as required by WCAG 1.4.13. Set label for a plain text tooltip, or use the tooltip snippet for rich content.

Examples of tooltip

location

The tooltip can be positioned in four directions relative to the trigger element: top, bottom, left or right. The component will attempt to keep the tooltip within the viewport by flipping its position if necessary (this can be disabled with avoidCollisions).

  • location: 'top' | 'bottom' | 'left' | 'right' = 'bottom'
tooltip.svelte
<div style="display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; padding: 2rem 0;">
	{#each ['top', 'bottom', 'left', 'right'] as location (location)}
		<kit:tooltip {location} label={`Location: ${location}`}>
			<kit:btn variant="outline">{location}</kit:btn>
		</kit:tooltip>
	{/each}
</div>

arrow variant

Add variant="arrow" to render a directional arrow on the tooltip panel.

  • variant: 'arrow' | undefined = ''
tooltip.svelte
<div style="display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; padding: 2rem 0;">
	{#each ['top', 'bottom', 'left', 'right'] as location (location)}
		<kit:tooltip {location} label={`Arrow ${location}`} variant="arrow">
			<kit:btn variant="outline">{location}</kit:btn>
		</kit:tooltip>
	{/each}
</div>

Custom content

Use the tooltip snippet to render any content inside the tooltip panel. When tooltip is set, forceMount is enabled automatically and label is ignored.

  • tooltip: Snippet | undefined = undefined
tooltip.svelte
<script lang="ts">
	import { Star } from 'lucide-svelte';
</script>

<kit:tooltip>
	{#snippet tooltip()}
		<div style="display: flex; align-items: center; gap: 0.375rem;">
			<kit:icon size="sm"><Star /></kit:icon>
			<span>Custom tooltip content</span>
		</div>
	{/snippet}
	<kit:btn>Rich tooltip</kit:btn>
</kit:tooltip>

The tooltip is displayed in the top layer of the page (Popover API): it is never cut by an overflow: hidden parent nor hidden behind a modal. It follows its activator when the page or a parent scrolls, flips to the opposite side when there is not enough space, and stays in the viewport.

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the components directly:

import { Tooltip } from 'lapikit/components';

API Reference

kit:tooltip

propstypedescriptiondefault
labelstringPlain text content of the tooltip.
locationenum'top''bottom''left''right'Preferred position relative to the trigger.'bottom'
variant'arrow'Renders a directional arrow on the tooltip panel.
delayDurationnumberHover delay before the tooltip appears (ms).850
openbooleanControls visibility. Bindable.false
disabledbooleanPrevents the tooltip from showing.false
forceMountbooleanKeeps the tooltip in the DOM when closed.false
avoidCollisionsbooleanFlips position to stay within the viewport.true
densityenum'dense''compact''default''comfortable''spacious'Padding, from -4px to +4px.'default'
roundedenum0'xs''sm''md''lg''xl''full'Border radius.'xs'
colorstring | false | { base?, active? }Background color, the text follows its on- color or a contrasted color.
tooltipSnippetRich content rendered inside the tooltip panel.
childrenSnippetThe trigger element.

Tooltips complement your Buttons or Icons by providing discreet but useful context for users.