Install
npm install svelte-tooltip-gca Requires svelte ^5.0.0 as a peer dependency.
npm package · Svelte action
Drop a use:tooltip action on any element. Auto light/dark
themes, smooth animation, mobile-friendly, and never hidden behind
other UI.
Install the package and attach the action to any HTML element.
npm install svelte-tooltip-gca Requires svelte ^5.0.0 as a peer dependency.
import { tooltip } from 'svelte-tooltip-gca'; Works in SvelteKit, Vite, and any Svelte 5 app.
<button use:tooltip={'Hello world'}>
Hover me
</button> Pass a string, or an options object for full control.
<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>Hover on desktop or tap on mobile. Tooltips flip when space is tight and stay above other content.
String shorthand for the most common case.
Preferred side with automatic flip near viewport edges.
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.
Resize the window or hover the edge buttons to see it in
action.
Tune show delay and animation duration.
Enable HTML for trusted markup (icons, emphasis).
Override auto detection with light or dark.
Pass a partial theme object — only override what you need.
On touch devices, tap toggles the tooltip (tap again or outside to dismiss). Long-press is optional and is cancelled if the finger moves — so it never fights with scrolling. On desktop, hover opens and a click dismisses.
Rendered via the native popover API in the
browser's top-layer — immune to overflow: hidden, stacking contexts, and
z-index wars.
By default tooltips use theme: 'auto'. Detection
order: page data-theme / .dark class → CSS color-scheme → prefers-color-scheme.
import { tooltip } from 'svelte-tooltip-gca';
import type { TooltipTheme } from 'svelte-tooltip-gca';
const myTheme: TooltipTheme = {
background: '#0ea5e9',
color: '#fff',
borderRadius: '12px',
shadow: '0 12px 30px rgba(14, 165, 233, 0.35)',
padding: '8px 14px',
fontSize: '13px'
};
// <button use:tooltip={{ content: 'Sky blue', theme: myTheme }}>…</button>| Property | Type | Description |
|---|---|---|
background | string | Panel background (color or gradient) |
color | string | Text color |
border | string | Border color |
shadow | string | CSS box-shadow |
borderRadius | string | Corner radius |
fontSize | string | Font size |
fontFamily | string | Font stack |
fontWeight | string | Font weight |
padding | string | Inner padding |
maxWidth | string | Max width |
arrowSize | string | number | Arrow size |
zIndex | number | string | Stacking order (default 9999) |
use:tooltip={params} accepts a string or a TooltipOptions object.
| Option | Type | Default | Description |
|---|---|---|---|
content | string | — | Tooltip text (required for object form) |
html | boolean | false | Render 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 |
offset | number | 8 | Gap between target and tooltip (px) |
delay | number | 120 | Show delay (ms) |
hideDelay | number | 80 | Hide delay (ms) |
arrow | boolean | true | Show pointing arrow |
animation | boolean | true | Enable fade/scale animation |
animationDuration | number | 160 | Animation duration (ms) |
disabled | boolean | false | Disable the tooltip |
class | string | '' | Extra CSS class on the tooltip |
maxWidth | number | string | theme default | Override max width |
touchBehavior | 'tap' | 'longpress' | 'tap' | How touch devices open the tip |
longPressDuration | number | 400 | Long-press threshold (ms) |
touchHideDelay | number | 3000 | Auto-hide on touch (0 = off) |
showOnFocus | boolean | true | Show on keyboard focus |
overflowBehavior | 'shift' | 'flip' | 'shift' | 'shift' keeps the preferred
side, slides the panel, and re-aims the
arrow. 'flip' tries opposite / perpendicular
sides (legacy). |
onShow / onHide | () => void | — | Lifecycle callbacks |
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';Escape, matching native popover
expectations.prefers-reduced-motion: reduce, the
enter/leave animation is disabled automatically.use:tooltip on any element — no wrapper components
required.
Detects dark/light from the page or system and switches automatically.
Tap or long-press on touch devices, with outside-dismiss and auto-hide.
Opens on focus, dismisses with Escape,
wired up via aria-describedby, and respects prefers-reduced-motion.
Uses the native popover API so tooltips live
in the browser's top-layer, never clipped, never behind a
modal.