Skip to content
Haze UI

Tooltip

Small text bubble that appears above or below a control on hover and on keyboard focus.

pnpm dlx shadcn@latest add @haze/tooltip
Open preview in a new tab
Livesmall script

When to use

  • Explaining what an icon-only button does
  • A short consequence or shortcut hint for a labelled control

When not to use

  • Information people need to complete the task; show it on the page
  • Anything with links or buttons inside; use popover
  • Touch-first screens, where hover does not exist

Installation

Add the Haze registry to components.json once, then install Tooltip with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/tooltip
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique on the page. Reference it from the control with aria-describedby.
text*string–Plain text, ideally under 80 characters.
side"top" | "bottom""top"Where the bubble appears.
align"start" | "center" | "end""center"Bubble alignment; use start or end near a screen edge.
classstring–Extra classes on the wrapper.
default slot*slot–One focusable control, such as a button or link.

Keyboard interactions

Tab
Focus the control and show the tooltip
Escape
Hide the tooltip without moving focus

Accessibility

  • The bubble fades in after a 150 ms hover delay, so passing over a control does not flash it.
  • The bubble has role="tooltip" and describes the control; it never replaces the control's own name, so icon buttons still need aria-label.
  • Meets WCAG 1.4.13: it shows on focus as well as hover, stays while the pointer is over it, and Escape hides it (the Escape part needs the script).
  • Tooltips form an instant group: once one has shown, moving to another within 300 ms shows it at once with no delay and no fade; after 300 ms idle the 150 ms delay returns. The group needs the script; without it every tooltip keeps the delay.
  • If the control has no aria-describedby, the script adds it; set it in the markup so it also works with scripts off.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Tooltip" with `npx shadcn@latest add @haze/tooltip`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Tooltip from "@/components/haze/ui/tooltip.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/tooltip.md

  • Customize with real content

    Adapt the Haze tooltip ui for our product. Replace the demo values of these props with our real content: id, text, side, align, class, default slot. Keep the layout, the heading level rules and these accessibility details: The bubble fades in after a 150 ms hover delay, so passing over a control does not flash it. The bubble has role="tooltip" and describes the control; it never replaces the control's own name, so icon buttons still need aria-label. Meets WCAG 1.4.13: it shows on focus as well as hover, stays while the pointer is over it, and Escape hides it (the Escape part needs the script). Tooltips form an instant group: once one has shown, moving to another within 300 ms shows it at once with no delay and no fade; after 300 ms idle the 150 ms delay returns. The group needs the script; without it every tooltip keeps the delay. If the control has no aria-describedby, the script adds it; set it in the markup so it also works with scripts off. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using tooltip, check it fits: use it when explaining what an icon-only button does; a short consequence or shortcut hint for a labelled control. Avoid it when information people need to complete the task; show it on the page; anything with links or buttons inside; use popover; touch-first screens, where hover does not exist. Alternatives: @haze/popover.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog