Skip to content

Tooltip

A short hint that appears when you hover over or focus a control. Same markup and props in every style: switch the style in the header to see it change.

Basic

Hover or focus the button. In HTML, add data-vin-tooltip="id" to the trigger and include vinui.js.

tooltip-basic.html
<button type="button" class="vin-btn vin-btn--outline" aria-describedby="tip-library" data-vin-tooltip="tip-library">Save</button>
<div class="vin-tooltip" id="tip-library" role="tooltip" popover="manual">Add to your library</div>

Icon buttons

For icon-only buttons the tooltip is the name, so it's linked with aria-labelledby.

tooltip-icons.html
<div style="display: flex; gap: 4px">
  <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon" aria-labelledby="tip-left" data-vin-tooltip="tip-left"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h16M4 12h10M4 18h14"/></svg></button>
  <div class="vin-tooltip" id="tip-left" role="tooltip" popover="manual">Align left</div>
  <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon" aria-labelledby="tip-center" data-vin-tooltip="tip-center"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h16M7 12h10M5 18h14"/></svg></button>
  <div class="vin-tooltip" id="tip-center" role="tooltip" popover="manual">Align centre</div>
  <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon" aria-labelledby="tip-right" data-vin-tooltip="tip-right"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h16M10 12h10M6 18h14"/></svg></button>
  <div class="vin-tooltip" id="tip-right" role="tooltip" popover="manual">Align right</div>
</div>

Sides

Top, right, bottom or left. Near the edge of the screen it flips to the side with room.

tooltip-sides.html
<button type="button" class="vin-btn vin-btn--outline vin-btn--sm" aria-describedby="tip-top" data-vin-tooltip="tip-top">Top</button>
<div class="vin-tooltip" id="tip-top" role="tooltip" popover="manual" data-side="top">On top</div>
<button type="button" class="vin-btn vin-btn--outline vin-btn--sm" aria-describedby="tip-rt" data-vin-tooltip="tip-rt">Right</button>
<div class="vin-tooltip" id="tip-rt" role="tooltip" popover="manual" data-side="right">On the right</div>
<button type="button" class="vin-btn vin-btn--outline vin-btn--sm" aria-describedby="tip-bottom" data-vin-tooltip="tip-bottom">Bottom</button>
<div class="vin-tooltip" id="tip-bottom" role="tooltip" popover="manual" data-side="bottom">Below</div>
<button type="button" class="vin-btn vin-btn--outline vin-btn--sm" aria-describedby="tip-lt" data-vin-tooltip="tip-lt">Left</button>
<div class="vin-tooltip" id="tip-lt" role="tooltip" popover="manual" data-side="left">On the left</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add tooltip
React
import { Tooltip } from "@/components/vin/tooltip";
Vue
import Tooltip from "@/components/vin/tooltip.vue";
Svelte
import Tooltip from "$lib/components/vin/tooltip.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/tooltip.json, which every framework version is tested against.

PropValuesDefaultIn HTML
content
The hint. Keep it short and plain text.
ReactNode—.vin-tooltip[role=tooltip][popover=manual]
side
Where it appears. It flips if there isn't room.
toprightbottomlefttopdata-side on .vin-tooltip
label
The tooltip is the control's name (icon buttons), not an extra description.
booleanfalsearia-labelledby instead of aria-describedby on the trigger
delay
Milliseconds before it shows on hover. Focus shows it at once.
number300—

Parts

React, Vue, SvelteHTML classes
<Tooltip>.vin-tooltip

Accessibility

  • role="tooltip", linked to the trigger with aria-describedby (or aria-labelledby when it is the name).
  • Shows on keyboard focus as well as hover, and Escape hides it without moving focus (WCAG 1.4.13).
  • You can move the pointer onto the tooltip without it closing.
  • Never put links or buttons in a tooltip: it can't be reached. Use a Popover for that.