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.
<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>import { Tooltip } from "@/components/vin/tooltip";
import { Button } from "@/components/vin/button";
export function TooltipBasic() {
return (
<Tooltip content="Add to your library">
<Button variant="outline">Save</Button>
</Tooltip>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Tooltip from "@/components/vin/tooltip.vue";
import Button from "@/components/vin/button.vue";
</script>
<template>
<Tooltip content="Add to your library">
<Button variant="outline">Save</Button>
</Tooltip>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Tooltip from "$lib/components/vin/tooltip.svelte";
import Button from "$lib/components/vin/button.svelte";
</script>
<Tooltip content="Add to your library">
{#snippet children(props)}<Button variant="outline" {...props}>Save</Button>{/snippet}
</Tooltip>Icon buttons
For icon-only buttons the tooltip is the name, so it's linked with aria-labelledby.
<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>import { Tooltip } from "@/components/vin/tooltip";
import { Button } from "@/components/vin/button";
const Icon = ({ d }: { d: string }) => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={d} /></svg>
);
export function TooltipIcons() {
return (
<div style={{ display: "flex", gap: 4 }}>
<Tooltip content="Align left" label>
<Button variant="ghost" size="icon"><Icon d="M4 6h16M4 12h10M4 18h14" /></Button>
</Tooltip>
<Tooltip content="Align centre" label>
<Button variant="ghost" size="icon"><Icon d="M4 6h16M7 12h10M5 18h14" /></Button>
</Tooltip>
<Tooltip content="Align right" label>
<Button variant="ghost" size="icon"><Icon d="M4 6h16M10 12h10M6 18h14" /></Button>
</Tooltip>
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Tooltip from "@/components/vin/tooltip.vue";
import Button from "@/components/vin/button.vue";
</script>
<template>
<div style="display: flex; gap: 4px">
<Tooltip content="Align left" label>
<Button variant="ghost" size="icon"><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>
</Tooltip>
<Tooltip content="Align centre" label>
<Button variant="ghost" size="icon"><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>
</Tooltip>
<Tooltip content="Align right" label>
<Button variant="ghost" size="icon"><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>
</Tooltip>
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Tooltip from "$lib/components/vin/tooltip.svelte";
import Button from "$lib/components/vin/button.svelte";
</script>
<div style="display: flex; gap: 4px">
<Tooltip content="Align left" label>
{#snippet children(props)}<Button variant="ghost" size="icon" {...props}><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>{/snippet}
</Tooltip>
<Tooltip content="Align centre" label>
{#snippet children(props)}<Button variant="ghost" size="icon" {...props}><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>{/snippet}
</Tooltip>
<Tooltip content="Align right" label>
{#snippet children(props)}<Button variant="ghost" size="icon" {...props}><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>{/snippet}
</Tooltip>
</div>Sides
Top, right, bottom or left. Near the edge of the screen it flips to the side with room.
<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>import { Tooltip } from "@/components/vin/tooltip";
import { Button } from "@/components/vin/button";
export function TooltipSides() {
return (
<>
<Tooltip content="On top" side="top"><Button variant="outline" size="sm">Top</Button></Tooltip>
<Tooltip content="On the right" side="right"><Button variant="outline" size="sm">Right</Button></Tooltip>
<Tooltip content="Below" side="bottom"><Button variant="outline" size="sm">Bottom</Button></Tooltip>
<Tooltip content="On the left" side="left"><Button variant="outline" size="sm">Left</Button></Tooltip>
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Tooltip from "@/components/vin/tooltip.vue";
import Button from "@/components/vin/button.vue";
</script>
<template>
<Tooltip content="On top" side="top"><Button variant="outline" size="sm">Top</Button></Tooltip>
<Tooltip content="On the right" side="right"><Button variant="outline" size="sm">Right</Button></Tooltip>
<Tooltip content="Below" side="bottom"><Button variant="outline" size="sm">Bottom</Button></Tooltip>
<Tooltip content="On the left" side="left"><Button variant="outline" size="sm">Left</Button></Tooltip>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Tooltip from "$lib/components/vin/tooltip.svelte";
import Button from "$lib/components/vin/button.svelte";
</script>
<Tooltip content="On top" side="top">
{#snippet children(props)}<Button variant="outline" size="sm" {...props}>Top</Button>{/snippet}
</Tooltip>
<Tooltip content="On the right" side="right">
{#snippet children(props)}<Button variant="outline" size="sm" {...props}>Right</Button>{/snippet}
</Tooltip>
<Tooltip content="Below" side="bottom">
{#snippet children(props)}<Button variant="outline" size="sm" {...props}>Bottom</Button>{/snippet}
</Tooltip>
<Tooltip content="On the left" side="left">
{#snippet children(props)}<Button variant="outline" size="sm" {...props}>Left</Button>{/snippet}
</Tooltip>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:
npx @vinish/ui add tooltipimport { Tooltip } from "@/components/vin/tooltip";import Tooltip from "@/components/vin/tooltip.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
contentThe hint. Keep it short and plain text. | ReactNode | — | .vin-tooltip[role=tooltip][popover=manual] |
sideWhere it appears. It flips if there isn't room. | toprightbottomleft | top | data-side on .vin-tooltip |
labelThe tooltip is the control's name (icon buttons), not an extra description. | boolean | false | aria-labelledby instead of aria-describedby on the trigger |
delayMilliseconds before it shows on hover. Focus shows it at once. | number | 300 | — |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.