Install
npm install svelte-tooltip-gcaRequires svelte ^5.0.0 as a peer dependency.
npm package · v1.1.0
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 Adjust parameters in real-time, test the animated feedback, and copy the generated Svelte 5 snippet.
Live interactive tooltip target
<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>Install the package and attach the action to any HTML element.
npm install svelte-tooltip-gcaRequires 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>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.
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.
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.
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>| Property | Type | Description |
|---|---|---|
background | string | Panel background color |
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. On anchor-positioning browsers it maps to native position-try-fallbacks. |
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.prefers-reduced-motion:
reduce is set.position-anchor + position-area + position-try-fallbacks), including during scroll, with zero
JavaScript. Older browsers silently fall back to the JS engine.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.
Uses the native popover API so tooltips live in the browser's top-layer.
On modern browsers CSS anchor positioning keeps the panel on target natively, so scroll repositioning is free. Older browsers use the JS engine.