Skip to main content

Tooltip

Info:Overlay html svelte astro Success: coverage 101/101

A hover/focus hint that floats a short description beside its trigger, on any of four sides.

Live demo

live · @xoji/astro

Tooltip

Placement

The hint floats on any of four sides — hover or focus a trigger to reveal it.

Floats above the trigger
Floats to the left
Pinned open for the showcase
Floats to the right
Floats below the trigger

Triggers and rich content

Any element can be the trigger; the content slot takes markup beyond plain text.

Save your changes Open settings underlined term A glossary definition with emphasis and a touch of detail. beta Even a badge can carry a hint

Tone

A tone colors the hint — a leading edge over the neutral surface by default, or a full soft / solid surface. The pinned row shows all three; hover the rest.

Leading tone edge
Soft toned surface
Solid toned surface
A gentle heads-up This cannot be undone A named-hue edge

Rich content

mode="rich" opens a roomier, left-aligned panel that wraps multi-line text and holds structured content — a detail readout, a progress bar, a definition.

Build #482

Success:passing

Deployed 2 minutes ago to production.

80%
derivation

Derivation

The process by which an algorithm maps a few anchors and knobs into a full, internally consistent token set — and yes, a tooltip can hold a whole paragraph when it needs to.

Tooltip wraps an interactive trigger and surfaces a short, supplementary hint on hover and on keyboard focus. The hint is linked to the trigger with aria-describedby so assistive tech announces it as the element's description, and it floats to one of four placement sides (top, bottom, left, right) over an elevated overlay surface with a pointing arrow.

It satisfies WCAG 1.4.13 Content on Hover or Focus: the hint is dismissible with Escape, hoverable (the pointer can travel onto the tooltip without it vanishing), and persistent (it stays until focus leaves or the pointer departs both trigger and tooltip). Tip text comes from the text prop, or richer markup from the content slot. The hint scales past a one-line label: a mode of rich opens it into a roomier, left-aligned panel that wraps multi-line text and holds structured content — a detail card, a stat or progress readout — size dials the padding, and a tone colors it, as a leading edge over the neutral overlay by default or as a fully soft/solid toned surface.

When to use

How this component composes with the rest of the set.

Wrap a Button (or any focusable control) as the trigger; icon-only buttons benefit most from a tooltip.
Keep the hint short and supplementary; never put essential or interactive content only in a tooltip.
For a label that must always be readable, use a visible caption instead; tooltips are progressive enhancement.

Props

7 props, straight from the manifest.

PropTypeDefaultBindingsDescription
text string
html svelte astro
The tip text. Use the `content` slot instead for richer markup.
placement Placement
top bottom left right
top
html svelte astro
Which side of the trigger the hint floats on.
open boolean false
html svelte astro
Reflects/controls visibility. Normally driven by hover and focus; settable to force the hint open.
tone Tone
accent neutral danger success warn info accent-2 accent-3 accent-4 red orange yellow green blue purple brown pink cyan gray white black
html svelte astro
Colors the hint with one of the register's tones. By default the surface stays a neutral overlay and the tone shows as a leading edge bar; pair with `variant` for a fully toned surface.
variant 'soft' | 'solid'
soft solid
html svelte astro
How a `tone` fills the surface. Omit for the neutral surface with a leading tone edge; `soft` washes the whole hint in the tone's soft tint; `solid` fills it with the tone. Both color the arrow to match. No effect without a `tone`.
mode 'hint' | 'rich'
hint rich
hint
html svelte astro
Content density. `hint` is the tight, single-line bubble for short text; `rich` is a roomier, left-aligned panel that wraps multi-line text and holds structured content (detail cards, stat or progress readouts).
size 'sm' | 'md'
sm md
sm
html svelte astro
Padding scale. `sm` is the compact default; `md` is roomier. Independent of `mode`.

Appearance

Variants

soft

.xoji-tooltip--soft

With a tone, washes the whole hint in the tone's soft tint with a matching border and arrow.

solid

.xoji-tooltip--solid

With a tone, fills the hint with the solid tone and its on-tone text and arrow.

Sizes

sm

default
.

Compact padding (the default).

md

.xoji-tooltip--md

Roomier padding.

States

open

.xoji-tooltip__content[data-open="true"]

Hint visible: fades in via the content's data-open flag while pointer or focus is on trigger or tooltip.

top

.xoji-tooltip--top .xoji-tooltip__content

Hint floats above the trigger; arrow points down.

bottom

.xoji-tooltip--bottom .xoji-tooltip__content

Hint floats below the trigger; arrow points up.

left

.xoji-tooltip--left .xoji-tooltip__content

Hint floats to the left of the trigger; arrow points right.

right

.xoji-tooltip--right .xoji-tooltip__content

Hint floats to the right of the trigger; arrow points left.

Anatomy

The named parts that make up the component, with their selectors.

tooltip

.xoji-tooltip

The inline wrapper around the trigger; carries the placement class and anchors the floating content.

content

.xoji-tooltip__content

The floating hint surface: an elevated overlay panel holding the tip text or content slot.

--font-sans --text-sm --weight-normal --leading-tight --fg-0 --surface-overlay --surface-overlay-border --border-thin --radius-sm --elevation-2 --space-1 --space-2 --space-8 --duration-fast --ease-standard

arrow

.xoji-tooltip__arrow

The rotated square nub pointing from the content back toward the trigger.

--space-1 --space-2 --surface-overlay --surface-overlay-border --border-thin

edge

.xoji-tooltip__content::before

The leading tone bar shown along the content's start edge when a tone is set without soft/solid; zero-width otherwise.

--space-1 --radius-sm

Tokens & coverage

What the component consumes, checked live against what the algorithm produces.

Success:fully covered 101/101 consumed tokens produced default register: 276 tokens

Live coverage check against the xoji-default register (derive(xojiDefault, { anchors })coverComponent(manifest, register)). Every token this component consumes must be a key the algorithm produces.

--accent --accent-2 --accent-2-bg --accent-2-fg --accent-2-text --accent-3 --accent-3-bg --accent-3-fg --accent-3-text --accent-4 --accent-4-bg --accent-4-fg --accent-4-text --accent-bg --accent-fg --accent-text --black --black-bg --black-fg --black-text --blue --blue-bg --blue-fg --blue-text --border-thin --brown --brown-bg --brown-fg --brown-text --cyan --cyan-bg --cyan-fg --cyan-text --danger --danger-bg --danger-fg --danger-text --duration-fast --ease-standard --elevation-2 --fg-0 --font-sans --gray --gray-bg --gray-fg --gray-text --green --green-bg --green-fg --green-text --info --info-bg --info-fg --info-text --leading-normal --leading-tight --neutral --neutral-bg --neutral-fg --neutral-text --orange --orange-bg --orange-fg --orange-text --pink --pink-bg --pink-fg --pink-text --purple --purple-bg --purple-fg --purple-text --radius-sm --red --red-bg --red-fg --red-text --space-1 --space-2 --space-3 --space-8 --success --success-bg --success-fg --success-text --surface-overlay --surface-overlay-border --text-sm --warn --warn-bg --warn-fg --warn-text --weight-normal --white --white-bg --white-fg --white-text --yellow --yellow-bg --yellow-fg --yellow-text

Slots

default
html svelte astro

The trigger element the tooltip describes.

content
html svelte astro

Rich hint markup, used in place of the text prop.

Accessibility

The hint carries role="tooltip" and is linked to the trigger via aria-describedby, so it is announced as the trigger's description.
Shows on BOTH pointer hover and keyboard focus, so the hint is reachable without a mouse.
WCAG 1.4.13 dismissible: Escape hides the hint while the trigger keeps focus.
WCAG 1.4.13 hoverable: the pointer can move onto the tooltip itself without it disappearing.
WCAG 1.4.13 persistent: the hint stays until focus leaves or the pointer departs both trigger and tooltip.
The arrow is decorative (aria-hidden); the binding warns at runtime when neither text nor a content slot is supplied.

Code

Placement and rich content

A plain-text hint above a button, and a rich-markup hint to the right of an icon button.

<xoji-tooltip text="Save your changes" placement="top">
	<button class="xoji-button xoji-button--solid xoji-button--accent">Save</button>
</xoji-tooltip>

<xoji-tooltip placement="right">
	<button class="xoji-button xoji-button--outline xoji-button--neutral" aria-label="Settings">
		<svg slot="icon-start" viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
			<path fill="currentColor" d="M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z" />
		</svg>
	</button>
	<span slot="content">Open <strong>settings</strong></span>
</xoji-tooltip>
<script lang="ts">
	import { Tooltip, Button } from "@xoji/svelte";
</script>

<Tooltip text="Save your changes" placement="top">
	<Button variant="solid" tone="accent">Save</Button>
</Tooltip>

<Tooltip placement="right">
	<Button variant="outline" tone="neutral" iconOnly ariaLabel="Settings">
		{#snippet iconStart()}
			<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
				<path fill="currentColor" d="M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z" />
			</svg>
		{/snippet}
	</Button>
	{#snippet content()}Open <strong>settings</strong>{/snippet}
</Tooltip>
---
import { Tooltip, Button } from "@xoji/astro";
---

<Tooltip text="Save your changes" placement="top">
	<Button variant="solid" tone="accent">Save</Button>
</Tooltip>

<Tooltip placement="right">
	<Button variant="outline" tone="neutral" iconOnly aria-label="Settings">
		<svg slot="icon-start" viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
			<path fill="currentColor" d="M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z" />
		</svg>
	</Button>
	<span slot="content">Open <strong>settings</strong></span>
</Tooltip>