Skip to content
Nana UI

Layout & Containers

Tooltip

A small contextual label that appears on hover or keyboard focus. Wrap the trigger in the default slot and pass the text via the content attribute (or the content slot for rich markup). Shows on hover and focus for accessibility, dismisses on Escape, and flips on the main axis when it would overflow the viewport.

View .md Download
Hover me

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add tooltip --framework web-components
npx @nana-tec/ui add tooltip --framework svelte

Lands in src/lib/components/ui/tooltip/ as NanaTooltip.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/tooltip";

Copied in with npx @nana-tec/ui add tooltip? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

<nana-tooltip content="Saves your changes">
<nana-button>Hover me</nana-button>
</nana-tooltip>
<script lang="ts">
import { NanaTooltip } from '$lib/components/ui/tooltip';
import { NanaButton } from '$lib/components/ui/button';
</script>
<NanaTooltip content="Saves your changes" placement="top">
{#snippet children()}
<NanaButton>Hover me</NanaButton>
{/snippet}
</NanaTooltip>

The trigger goes in the children snippet, wrapped in an inline span that carries the hover, focus and Escape handling plus aria-describedby.

Top Right Bottom Left
Dark Light Success Danger Info Warning

Properties

PropertyAttributeTypeDefaultDescription
arrowarrowbooleanfalseShow a pointing arrow.
closeDelayclose-delaynumber0Delay before hiding on leave/blur, in ms.
contentcontentstring''Plain-text tooltip content. Ignored when the content slot is used.
disableddisabledbooleanfalseDisable the tooltip entirely.
openopenbooleanfalseOpen state (use with trigger="manual" for full control).
openDelayopen-delaynumber300Delay before showing on hover/focus, in ms.
placementplacementTooltipPlacement'top'Where the tooltip sits relative to the trigger.
sizesizeTooltipSize'md'Size scale.
triggertriggerTooltipTrigger'hover'What opens the tooltip. hover also responds to keyboard focus.
variantvariantTooltipVariant'dark'Colour theme.

Methods

MethodDescription
hide(): voidClose the tooltip immediately.
show(): voidOpen the tooltip immediately.
toggle(): voidToggle the tooltip.

Events

EventDescription
nana-showFired when the tooltip opens
nana-hideFired when the tooltip closes

Slots

SlotDescription
(default)The trigger element the tooltip describes
contentRich tooltip content (overrides the content attribute)

CSS parts

PartDescription
::part(base)The positioning container
::part(body)The tooltip bubble
::part(arrow)The arrow
::part(trigger)The wrapper around the slotted trigger content

CSS custom properties

PropertyDescription
--nana-tooltip-bgBubble background
--nana-tooltip-colorBubble text colour
--nana-tooltip-max-widthMax bubble width before wrapping
--nana-tooltip-borderBorder shorthand for the bubble
--nana-tooltip-easeEasing curve for both the show and hide transitions
--nana-tooltip-enter-durationHow long the tooltip takes to appear
--nana-tooltip-exit-durationHow long the tooltip takes to disappear
--nana-tooltip-paddingBubble padding
--nana-tooltip-radiusBubble corner radius
--nana-tooltip-shadowBubble shadow
--nana-tooltip-zStacking order for the bubble

NanaTooltip

PropTypeDefault
contentrequiredstring
placementTooltipPlacement'top'
disabledbooleanfalse
openDelaynumber
closeDelaynumber
openbind:booleanfalse
onOpenChange(open: boolean) => void
childrenSnippet