npm package · v1.1.0

Tooltips that stay
in the flow.

A small, dependency-free use:tooltip action for Svelte 5. It handles themes, touch, keyboard focus, animation, and viewport-aware positioning for you, anchoring the panel natively via CSS anchor positioning on modern browsers.

$ npm install svelte-tooltip-gca
Try Live Playground
Svelte 5 Runes native
Top layer Popover API
0 deps Runtime lean
CSS anchor Native positioning
Live preview Ready
Hover, focus, or tap a target The arrow re-aims as the panel shifts.

Interactive Playground

Adjust parameters in real-time, test the animated feedback, and copy the generated Svelte 5 snippet.

Show Delay 120ms
Animation Duration 200ms
Offset Gap 8px

Live interactive tooltip target

svelte
<script>
  import { tooltip } from 'svelte-tooltip-gca';
</script>

<button
  use:tooltip={{
    content: '✨ Smooth Svelte 5 tooltip!',
    placement: 'top',
    delay: 120,
    animationDuration: 200,
    offset: 8,
    arrow: true,
    theme: {
      "background": "#ff3e00",
      "color": "#1b1f24",
      "border": "transparent",
      "shadow": "0 8px 20px rgba(255, 62, 0, 0.25)",
      "borderRadius": "8px",
      "padding": "8px 14px",
      "fontSize": "13px",
      "fontWeight": "600"
}
  }}
>
  Hover Me
</button>

Quick start

Install the package and attach the action to any HTML element.

1

Install

bash
npm install svelte-tooltip-gca

Requires svelte ^5.0.0 as a peer dependency.

2

Import

ts
import { tooltip } from 'svelte-tooltip-gca';

Works in SvelteKit, Vite, and any Svelte 5 app.

3

Use

svelte
<button use:tooltip={'Hello world'}>
  Hover me
</button>

Pass a string, or an options object for full control.

Minimal example

svelte
<script>
  import { tooltip } from 'svelte-tooltip-gca';
</script>

<button use:tooltip={'Saved to drafts'}>
  Save
</button>

<button
  use:tooltip={{
    content: 'Delete permanently',
    placement: 'right',
    delay: 200
  }}
>
  Delete
</button>

Live examples

Basic

String shorthand for the most common case.

Placements

Preferred side with automatic flip near viewport edges.

Smart positioning

By default (overflowBehavior: 'shift') the tooltip stays on its preferred side, slides to remain in the viewport, and the arrow re-aims at the target.

Delay & animation

Tune show delay and animation duration.

Rich content

Enable HTML for trusted markup (icons, emphasis).

Forced themes

Override auto detection with light or dark.

Custom themes

Pass a partial theme object — only override what you need.

Mobile / touch

On touch devices, tap toggles the tooltip (tap again or outside to dismiss). Long-press is optional and is cancelled if the finger moves.

Overflow-safe

Rendered via the native popover API in the browser's top-layer — immune to overflow: hidden and stacking context issues. Scroll tracking is native too, via CSS anchor positioning where supported.

Theming

Custom theme object

ts
import { tooltip } from 'svelte-tooltip-gca';
import type { TooltipTheme } from 'svelte-tooltip-gca';

const myTheme: TooltipTheme = {
  background: '#ff3e00',
  color: '#1b1f24',
  borderRadius: '8px',
  shadow: '0 8px 20px rgba(255, 62, 0, 0.25)',
  padding: '8px 14px',
  fontSize: '13px'
};

// <button use:tooltip={{ content: 'Svelte orange', theme: myTheme }}>…</button>

Theme properties

PropertyTypeDescription
backgroundstringPanel background color
colorstringText color
borderstringBorder color
shadowstringCSS box-shadow
borderRadiusstringCorner radius
fontSizestringFont size
fontFamilystringFont stack
fontWeightstringFont weight
paddingstringInner padding
maxWidthstringMax width
arrowSizestring | numberArrow size
zIndexnumber | stringStacking order (default 9999)

API reference

use:tooltip={params} accepts a string or a TooltipOptions object.

OptionTypeDefaultDescription
contentstring—Tooltip text (required for object form)
htmlbooleanfalseRender content as HTML (trusted only)
placement'top' | 'bottom' | 'left' | 'right''top'Preferred side; auto-flips if needed
theme'auto' | 'light' | 'dark' | TooltipTheme'auto'Built-in mode or custom theme
offsetnumber8Gap between target and tooltip (px)
delaynumber120Show delay (ms)
hideDelaynumber80Hide delay (ms)
arrowbooleantrueShow pointing arrow
animationbooleantrueEnable fade/scale animation
animationDurationnumber160Animation duration (ms)
disabledbooleanfalseDisable the tooltip
classstring''Extra CSS class on the tooltip
maxWidthnumber | stringtheme defaultOverride max width
touchBehavior'tap' | 'longpress''tap'How touch devices open the tip
longPressDurationnumber400Long-press threshold (ms)
touchHideDelaynumber3000Auto-hide on touch (0 = off)
showOnFocusbooleantrueShow on keyboard focus
overflowBehavior'shift' | 'flip''shift''shift' keeps the preferred side, slides the panel, and re-aims the arrow. On anchor-positioning browsers it maps to native position-try-fallbacks.
onShow / onHide() => void—Lifecycle callbacks

Exports

ts
import {
  tooltip,          // Svelte action
  lightTheme,       // default light theme object
  darkTheme,        // default dark theme object
  detectDarkMode,   // () => boolean
  resolveTheme      // resolve mode/partial → full theme
} from 'svelte-tooltip-gca';

import type {
  TooltipParams,
  TooltipOptions,
  TooltipTheme,
  TooltipThemeMode,
  TooltipPlacement
} from 'svelte-tooltip-gca';

Behavior notes

  • Escape dismisses: An open tooltip closes when you press Escape.
  • Reduced motion: Disables animations automatically when prefers-reduced-motion: reduce is set.
  • Native anchoring: When the browser supports CSS anchor positioning (Baseline 2026: Chrome/Edge 125+, Firefox 145+, Safari 27+), the tooltip is glued to its target by the browser itself (position-anchor + position-area + position-try-fallbacks), including during scroll, with zero JavaScript. Older browsers silently fall back to the JS engine.
  • Long-press cancels on movement: Cancels opening if a touch turns into a scroll or drag.
  • Live updates: Parameter reactive updates re-render and reposition tooltips seamlessly.

FAQ

Highlights:

✨

Svelte 5 action

use:tooltip on any element — no wrapper components required.

🌓

Auto theme

Detects dark/light from the page or system and switches automatically.

📱

Mobile ready

Tap or long-press on touch devices, with outside-dismiss and auto-hide.

🎹

Keyboard and a11y

Opens on focus, dismisses with Escape, wired up via aria-describedby.

🚀

Top-layer rendering

Uses the native popover API so tooltips live in the browser's top-layer.

🧭

Native anchoring

On modern browsers CSS anchor positioning keeps the panel on target natively, so scroll repositioning is free. Older browsers use the JS engine.