Zubra UI
Code for
GitHub

tool-tip

A short description shown when its trigger is hovered or focused: the trigger is the slotted element, and the tip describes it (aria-describedby), so a screen reader reads it with the trigger's name. It shows after delay milliseconds, stays while the pointer is over it, and Escape hides it without moving focus (WCAG 1.4.13). It sits in the top layer (popover), placed above the trigger by CSS anchor positioning, or by script where that isn't supported.

This one has no events: it shows what it's given.

Source: tool-tip.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tool-tip.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tool-tip.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tool-tip.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tool-tip.json
One file, no dependencies (4.2 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tool-tip.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tool-tip.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tool-tip.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tool-tip.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tool-tip.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tool-tip.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tool-tip.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tool-tip.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/tool-tip.js"></script>

The compiled install writes src/components/zubra/tool-tip.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<tool-tip text="Saved to your drafts. Only you can see it.">
  <button type="button">Save draft</button>
</tool-tip>

<script type="module">
  import './components/zubra/tool-tip.js';
</script>
Example.jsx
import './components/zubra/tool-tip.js';

export function ToolTipExample() {
  return (
    <tool-tip text="Saved to your drafts. Only you can see it.">
      <button type="button">Save draft</button>
    </tool-tip>
  );
}
Example.vue
<script setup>
import './components/zubra/tool-tip.js';
</script>

<template>
  <tool-tip text="Saved to your drafts. Only you can see it.">
    <button type="button">Save draft</button>
  </tool-tip>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/tool-tip.js';
</script>

<tool-tip text="Saved to your drafts. Only you can see it.">
  <button type="button">Save draft</button>
</tool-tip>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/tool-tip.js';

@Component({
  selector: 'app-tool-tip-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <tool-tip text="Saved to your drafts. Only you can see it.">
      <button type="button">Save draft</button>
    </tool-tip>
  `,
})
export class ToolTipExample {

}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
textstring""
delaynumber300
Slots
SlotFor
(default)The trigger: one focusable element.
contentThe tip (defaults to text).

Size

1.5 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.1 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour