tooltip

tooltip shows a short line of text about a control. It shows when the pointer rests on the control, or when the keyboard focuses it.

onChange called 0 time(s)

import { lucide, tooltip } from '@markless/ui';export default function TooltipBasic() @{	<tooltip.root class="tooltip">		<tooltip.trigger class="save">			<lucide.save class="icon" aria-hidden="true" />			Save		</tooltip.trigger>		<tooltip.content class="tip">Keeps a copy in your drafts</tooltip.content>	</tooltip.root>;}

Rest the pointer on Save, or Tab to it, and the tip shows. Change delay to set the wait. Turn on open to show the tip from the start.

A tooltip describes a control. It does not name it. The trigger points at the tip with aria-describedby, even while the tip is hidden. So a screen reader reads the tip when focus reaches the button, whether the tip shows or not.

When to use it

Use tooltip for a hint that a person can live without, such as what a button does. The tip holds text only. If it needs a link or a button, use hovercard or popover instead. Touch screens never show a tooltip, so do not put anything there that a person needs.

Parts

tooltip anatomy
Anatomy perspectiveFlat
Layers
Save your changesSave
tooltip.root

The tooltip itself; the trigger and the tip go inside it, in that order.

  • tooltip.root holds whether the tip shows, and the wait before it shows. It renders a <div> around both parts.
  • tooltip.trigger is the <button> the tip describes.
  • tooltip.content is the tip, with role="tooltip". A hidden tip gets hidden. It stays in the page, so aria-describedby still finds it.

When the tip shows and hides

The family's tests check each of these:

  • A resting pointer waits for delay before the tip shows. The default is 600 milliseconds. Set delay={0} to show it at once.
  • Keyboard focus shows the tip at once. Focus from a mouse press does not show it.
  • The pointer can move from the trigger onto the tip. The tip stays.
  • The tip hides when the pointer leaves both parts. If the keyboard focused the trigger, the tip stays until focus leaves.
  • A showing tip never hides on a timer.
  • A press on the trigger hides the tip, and it stays hidden.
  • A touch never shows the tip.
  • Showing one tip hides another tip that keyboard focus held open. A menu that opens hides the tip too.

Where the tip sits

The tip sits above its trigger. That default is a CSS rule inside @layer markless. One rule of yours outside a layer beats it:

.tip {
	position-area: inline-end;
}

The tooltip has no prop for its position. Placement is CSS. Styling has a live example. Two tooltips on one page each sit against their own trigger. The tip also finds its trigger when you write the content part before the trigger part.

Styling hooks

Attribute On Present when
ui-open root, trigger, content The tip is showing.
ui-closed root, trigger, content The tip is hidden.

tooltip.content also carries an overlay attribute. The family uses it to place the tip on top of the page. It is not a styling hook.

Keyboard

Key What it does
Tab to the trigger Shows the tip at once. Tab away and the tip hides.
Escape Hides the tip. Focus stays on the trigger.

Gotchas

API reference

tooltip.root

openboolean
Whether the tooltip is showing. Omit it and it starts hidden. Default false.
delaynumber
How long the pointer must rest on the trigger before the tooltip shows, in milliseconds. Omit it and it is 600. Keyboard focus shows it at once, with no wait; the focus a click gives the trigger shows nothing. Default 600.
onChange(open: boolean) => void
Called with the new value when the tooltip shows or hides, including when Escape or a press elsewhere hides it.

tooltip.trigger

No props of its own.

tooltip.content

No props of its own.