# Tooltip (`.z-tooltip`)

> Singleton text hint shown on hover or keyboard focus of any `data-tooltip` element, positioned with Floating UI.

- **Kind:** css
- **Category:** overlays

## CSS Variables

| Variable | Default | Scope | Affects | Description |
| --- | --- | --- | --- | --- |
| `--z-tooltip-bg` | `var(--z-primary)` | `.z-tooltip` | `background-color` | Background base color, mixed with transparency using `--z-tooltip-bg-o`. |
| `--z-tooltip-bg-o` | `100%` | `.z-tooltip` | `background-color` | Background opacity percentage used in the background color mix. |
| `--z-tooltip-blur` | `var(--z-global-blur)` | `.z-tooltip` | `-webkit-backdrop-filter`, `backdrop-filter` | Backdrop blur radius used by `.z-tooltip-blur`. |
| `--z-tooltip-color` | `var(--z-primary-f)` | `.z-tooltip` | `color` | Text base color, mixed with transparency using `--z-tooltip-color-o`. |
| `--z-tooltip-color-o` | `100%` | `.z-tooltip` | `color` | Text opacity percentage used in the text color mix. |
| `--z-tooltip-font-size` | `0.75rem` | `.z-tooltip` | `font-size` | Font size of the tooltip text. |
| `--z-tooltip-line-height` | `1rem` | `.z-tooltip` | `line-height` | Line height of the tooltip text. |
| `--z-tooltip-max-width` | `208px` | `.z-tooltip` | `max-width` | Maximum width of the tooltip box; text wraps at this width. |
| `--z-tooltip-padding` | `0.375rem 0.75rem` | `.z-tooltip` | `padding` | Inner padding of the tooltip box. |
| `--z-tooltip-radius` | `var(--z-global-radius)` | `.z-tooltip` | `border-radius` | Corner radius of the tooltip box. |
| `--z-tooltip-shadow` | `var(--z-global-shadow-small)` | `.z-tooltip` | `box-shadow` | Box shadow of the tooltip box. |
| `--z-tooltip-slide-x` | `0` | `.z-tooltip[data-side='top']` | — | Horizontal enter-slide offset for the current side, used by the `z-tooltip-in` keyframes. |
| `--z-tooltip-slide-y` | `4px` | `.z-tooltip[data-side='top']` | — | Vertical enter-slide offset for the current side, used by the `z-tooltip-in` keyframes. |
| `--z-tooltip-z-index` | `1030` | `.z-tooltip` | `z-index` | Stacking order of the tooltip element. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-tooltip:hide` | — | `{ trigger: HTMLElement; tooltip: HTMLDivElement }` | Fires on the trigger when its tooltip is hidden, with the same detail shape as `show`. |
| `z-tooltip:show` | — | `{ trigger: HTMLElement; tooltip: HTMLDivElement }` | Fires on the trigger when its tooltip is shown. Detail carries `trigger` and `tooltip` (the shared tooltip element). |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-side` | — | `descendant` | `marker` | Set by the singleton on the tooltip element to the resolved placement side (`top`, `bottom`, `left`, `right`); selects fixed positioning and the enter-animation direction. |
| `data-tooltip` | — | `external-trigger` | `config` | Activates the tooltip on the element. The value is the tooltip text, or an option string with `title`/`text`, `pos`/`placement`, `offset`, `delay`, `flip`, `shift`, `blur`, `cls`, and `stl`. A native `title` attribute is stashed and used as fallback text. |

## CSS Classes

| Class | Role | Applies to | Description |
| --- | --- | --- | --- |
| `.z-tooltip` | `root` | `.z-tooltip` | Root class of the shared tooltip element (`div#z-tooltip-singleton` appended to `body`); hidden until the singleton adds `z-active`. |
| `.z-tooltip-blur` | `modifier` | `.z-tooltip` | Applies a backdrop blur and a slightly translucent background; enabled by the `blur` option. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `Escape` | Hides the visible (or pending) tooltip. | — |

## Accessibility

> While shown, the trigger gets `aria-describedby="z-tooltip-singleton"` and the tooltip element has `role="tooltip"`; both are restored on hide.

> Keyboard focus shows the tooltip immediately when `:focus-visible` matches, so keyboard users get the same hint as pointer users.

> A stashed native `title` is restored when the tooltip hides, keeping the browser fallback available.

## Notes

- One shared tooltip element is reused for every trigger; it is created on first use and kept positioned with Floating UI `autoUpdate`.
- Hover shows after `delay` (default 100 ms); moving to another trigger within 350 ms of the last hide shows immediately (warmup).
- Touch pointers are ignored, disabled triggers are skipped, and pointerdown hides the tooltip.
- Placement names map to Floating UI placements (`top-left` → `top-start`, etc.); `flip` and `shift` keep the tooltip inside the viewport.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)
