Tooltip

Free

Hover/click/focus/long-press tooltip with 12 placements, rich title · description · keys content, nine looks, tooltip groups, a controlled open, anchors and three animations — and a Pro twin that can be hovered, focused and follows the cursor.

</>sv-tooltip tooltipoverlayhint
import { SvTooltipComponent } from '@styloviz/overlays/tooltip';

Demo & usage

Basic usage

Usage example — open the gallery for the full interactive demo.

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Click trigger, custom width

example.htmlAngular
<sv-tooltip text="Copied to clipboard" trigger="click" position="right" [maxWidth]="220">
  <button>Copy</button>
</sv-tooltip>

Track visibility

example.htmlAngular
<sv-tooltip text="Save changes" (visibleChange)="onTooltipToggle($event)">
  <button>Save</button>
</sv-tooltip>

Inside a table cell or card — portalled by default

example.htmlAngular
<!-- The bubble renders in a body portal positioned by measurement, so an
     ancestor with overflow: hidden cannot clip it: it flips when the preferred
     side does not fit and is clamped to the viewport. [portal]="false" keeps
     it inside the trigger wrapper instead. -->
<td class="overflow-hidden">
  <sv-tooltip text="Unpaid since 12 May" position="top">
    <button>Overdue</button>
  </sv-tooltip>
</td>

Explaining a disabled control

example.htmlAngular
<!-- A natively disabled button fires no pointer events and takes no focus,
     so a plain tooltip on it never appears. The preset takes the dead
     control out of hit-testing and gives the wrapper the tab stop.
     Prefer aria-disabled="true" when the control is yours - it needs none of
     this. Never use the preset around an ENABLED control. -->
<sv-tooltip text="Only admins can delete projects" [forDisabledControl]="true">
  <button disabled>Delete</button>
</sv-tooltip>

When to use

  • Revealing a short, supplementary hint on hover/focus of a control.
  • Explaining icon-only buttons or truncated labels.
  • For rich, interactive content use a Popover (a hint with one link in it is `sv-tooltip-pro` with `[interactive]`); for persistent info, inline text.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Inputs

NameTypeDefaultDescription
textstring''Tooltip text content.
positionTooltipPosition'top'Position relative to the trigger.
variantTooltipVariant'dark'Color variant.
sizeTooltipSize'md'Size — controls font and padding.
triggerTooltipTrigger'hover'What triggers the tooltip.
maxWidthnumber | null240Max width of the tooltip bubble (px); the text wraps at it. `null` keeps the bubble on one line however long the text is.
delaynumber0Delay before showing (ms).
disabledbooleanfalseWhether the tooltip is disabled.
customClassstring''Extra CSS classes merged onto the tooltip bubble.
portalbooleantrueRender the bubble in a `<body>` portal, positioned by measurement — on by default. The in-place bubble clips: an absolutely positioned child is clipped by any ancestor with `overflow: hidden` — every table cell, card and scroll area in a dashboard — and it is placed by CSS classes alone, so it cannot see the viewport edge. The portal moves the bubble to the end of `<body>` and positions it with `svPositionAnchored` (the arithmetic Popover and Dropdown Menu use): it escapes the clip, flips when it does not fit, and is clamped to the viewport. `[portal]="false"` keeps the bubble inside the trigger wrapper, for a host that styles it by its position in the DOM. It was the default in earlier versions.
flipbooleantrueFlip to the opposite side when the preferred one does not fit. Only meaningful when portalled (the default) — the in-place path has no measurement to decide with.
offsetnumber8Gap between trigger and bubble, in px, when portalled. Matches the `mb-2` / `mt-2` the in-place path uses, so `[portal]="false"` does not move the bubble.
fullWidthbooleanfalseStretch the trigger wrapper to the width of its container. The wrapper is `inline-flex` by default, which is right for a word, an icon or a button — it hugs whatever it wraps. It is wrong the moment the trigger is a card in a grid or flex row: the wrapper becomes the track item and shrinks to its content, so the card does not fill its cell. Set this to lay the wrapper out as a full-width block instead.
forDisabledControlbooleanfalseMake the tooltip work over a control the browser has `disabled`. A disabled control fires no pointer events and takes no focus, so the tooltip explaining WHY it is disabled is the one tooltip in the kit that could never appear — and it is also the one users most need. The browser does not dispatch mouse events whose target is a disabled form control, so nothing reaches this wrapper either; and the control is out of the tab order, so the keyboard path is gone as well. What this does is two lines and both are necessary: the projected content gets `pointer-events: none`, which takes the disabled control out of hit-testing so hover and tap land on the WRAPPER; and the wrapper takes `tabindex="0"`, so the explanation is reachable by keyboard at all. `aria-describedby` already lives on the wrapper, so a screen-reader user who lands there hears the reason. Prefer `aria-disabled="true"` over `disabled` and you need none of this. A control marked `aria-disabled` stays focusable and keeps firing pointer events — it is announced as unavailable, your handler ignores the click, and every tooltip path works untouched. This preset is for the control you cannot change: a third-party component, or markup that is not yours. Do NOT set it around an ENABLED control. `pointer-events: none` applies to whatever is projected, so the control's own clicks stop working. Dev mode warns when the projected content does not look disabled.
titlestring''A bold first line above `text`, which becomes the description.
kbdreadonly string[][]Keys to show on the bubble's end — a shortcut, drawn with `sv-kbd`.
arrowbooleantrueDraw the arrow pointing at the trigger.
iconstring''An icon before the content — a `@styloviz/icons` name.
statusTooltipStatus | nullnullA coloured status dot before the content.
openboolean | undefinedundefinedControlled visibility (two-way). Unbound, the tooltip shows and hides on its trigger. Bound, the trigger only REQUESTS — through `openChange` — and the bubble follows `open`, so a host can drive it: a slider showing its value while dragging, a guided tour.
anchorElement | TooltipPoint | nullnullPosition against this element or viewport point instead of the trigger — a slider's thumb, a chart's crosshair. Implies the portal.
touchTooltipTouch'tap'What a touch does where nothing can hover: tap to toggle, long-press, or nothing.
animationTooltipAnimation'scale'How the bubble enters and leaves; instant under reduced motion.

Outputs

EventPayload typeDescription
openChangebooleanA visibility change asked for by the trigger — the controlled `open` decides.
visibleChangebooleanEmitted whenever the tooltip's visibility changes (true = shown, false = hidden).

<sv-tooltip-pro>

Also in this family — SvTooltipProComponent from @styloviz-pro/overlays.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Inputs

NameTypeDefaultDescription
textstring''The tooltip's text — or its description, under a `title`.
positionTooltipPosition'top'Where the bubble sits: one of the 12 placements.
variantTooltipVariant'dark'The bubble's look.
sizeTooltipSize'md'Bubble size: padding and type.
triggerTooltipTrigger'hover'What shows it: hover (and focus), click, or focus only.
maxWidthnumber | null240Width cap in px; `null` keeps it on one line.
delaynumber0Delay before it shows, in ms.
disabledbooleanfalseSwitch the tooltip off — the trigger stays, the bubble never shows.
customClassstring''Extra classes for the bubble.
portalbooleantrueRender the bubble in a body portal (never clipped); `false` keeps it in place.
flipbooleantrueFlip to the other side when it does not fit (portalled).
offsetnumber8Gap between trigger and bubble, in px.
fullWidthbooleanfalseStretch the trigger wrapper to the full width.
forDisabledControlbooleanfalseExplain a disabled control (the wrapper takes the tab stop).
titlestring''A bold first line above `text`.
kbdreadonly string[][]Keys to show on the bubble's end.
arrowbooleantrueDraw the arrow.
iconstring''An icon before the content.
statusTooltipStatus | nullnullA status dot before the content.
openboolean | undefinedundefinedControlled visibility (two-way). Bound, the trigger only requests through `openChange` and the bubble follows `open`.
anchorElement | TooltipPoint | nullnullPosition against this element or point instead of the trigger.
touchTooltipTouch'tap'What a touch does where nothing can hover.
animationTooltipAnimation'scale'How the bubble enters and leaves.
interactivebooleanfalseThe bubble can be hovered, focused and used: it stays while the pointer travels onto it (within `hideDelay`) and while focus is inside it; Tab from the trigger moves into it. Implies the portal.
hideDelaynumber200How long an interactive bubble waits before hiding once the pointer leaves, in ms.
followCursorbooleanfalseThe bubble follows the pointer across the trigger. Implies the portal.

Outputs

EventPayload typeDescription
visibleChangebooleanThe bubble appeared or went away.
openChangebooleanA visibility change asked for — the controlled `open` decides.

Customization & theming

  • Twelve placements (`top`, `top-start` … `right-end`; `start`/`end` mirror in RTL), nine looks (dark · light · primary · danger · success · warning · inverted · glass · value) and three sizes (sm · md · lg).
  • Rich content: a `title` above the text, `kbd` keys, an `icon`, a `status` dot, or your own markup in a `[svTooltipContent]` template; `[arrow]` toggles the pointer and `animation` is `fade` · `scale` · `shift`.
  • `[svTooltipGroup]` on a toolbar: the first tooltip waits for `groupDelay`, the next one along shows at once (within `skipDelay`), and only one is open at a time. `[open]` controls it from outside; `[anchor]` points it at another element or a viewport point.
  • Hover, click or focus triggers — and on a pointer that cannot hover, a `hover` tooltip becomes tap-to-toggle by itself, with the show delay skipped and a press anywhere else dismissing it (`touch="hold"` makes it a long-press instead, `touch="off"` leaves it out on touch). A `focus` or `click` trigger is left alone.
  • Configurable show/hide delay.
  • `customClass` on the bubble; `visibleChange` output.
  • The bubble renders in a `<body>` portal positioned by measurement (the default; `[portal]="false"` keeps it in place) — the same arithmetic Popover and Dropdown Menu use. It escapes an `overflow: hidden` ancestor (every table cell, card and scroll area), flips with `[flip]`, is clamped to the viewport, keeps its arrow over the trigger when clamped, and re-anchors on scroll of any ancestor.
  • A portalled tooltip paints in the ambient tooltip band, so it clears a dialog it appears inside — and it never becomes the surface Escape closes.
  • `[forDisabledControl]="true"` — the disabled-control preset: the projected control gets `pointer-events: none` so hover and tap land on the wrapper, and the wrapper becomes a tab stop described by the tooltip from the start (Enter/Space toggle a `click` tooltip there). Dev mode warns when the projected content is not actually disabled.
  • Pro (`sv-tooltip-pro`): `[interactive]` keeps the bubble open while the pointer is on it (after `hideDelay`) or focus is inside, so links in it work and Tab from the trigger goes in; `[followCursor]` makes it ride with the pointer over a chart or a timeline.

Best practices

  • Do: Keep tooltip text to a few words — it's a hint, not documentation.
  • Do: Ensure it appears on keyboard focus, not hover alone (it does).
  • Do: Leave the portal on (the default) whenever the trigger sits inside a table cell, a card, or anything that scrolls or hides its overflow; `[portal]="false"` puts the bubble back inside the trigger wrapper, where that ancestor clips it and a viewport edge cuts it off.
  • Don't: Don't hide essential information in a tooltip — many users never trigger it, and a touch user only finds it by tapping. If the text is needed to complete the task, put it in visible helper text, or in a click-opened Popover (`[interactive]="false"` for a read-only note).
  • Don't: Don't put interactive content in a `sv-tooltip` — links, buttons, form fields. Its bubble is `pointer-events-none`, so even markup projected through `[svTooltipContent]` cannot be clicked: that is structural, not a guideline. A hint with one link in it is `sv-tooltip-pro` with `[interactive]="true"`; anything more is a Popover.

Accessibility

  • Shows on keyboard focus, not just hover, and emits `visibleChange` on every transition.
  • Associated via aria-describedby; dismissible with Esc.
  • It works on touch, which a hover tooltip does not — worse, it half-works: mobile browsers synthesise `mouseenter` on tap, so the tap meant to activate the trigger raises the tooltip over the control just pressed, and with no `mouseleave` coming it stays there. Where hovering is unavailable the tooltip switches to tap-to-toggle, skips the delay (a tap is deliberate), and dismisses on a press elsewhere — there is no `mouseleave` on a finger and no Escape key on a phone. It follows a pointer that changes mid-session, because a convertible laptop folds.
  • Forced colours: every bubble — the glass one included — keeps a `CanvasText` edge, because forced colours repaint its fill as Canvas and remove its ring.

Feedback on Tooltip

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.