A tooltip is a small overlay describing the element it points at. It opens on hover and on focus, and it closes on its own as soon as either leaves.
Anatomy
Section titled “Anatomy”-
Trigger the element the tooltip is about. It is yours —SLATime to first response, in business hours.Time to first response, in business hours.SLATime to first response, in business hours.Time to first response, in business hours.triggertakes any element and Tooltip only puts a ref on it. -
Container (when open) the surface. It carries the message and points at the trigger with an arrow.SLATime to first response, in business hours.Time to first response, in business hours.SLATime to first response, in business hours.Time to first response, in business hours. -
Message (when open) one short sentence. It is rendered twice — once here and once in a hidden node for screen readers — so it can never be read by only one of them.SLATime to first response, in business hours.Time to first response, in business hours.SLATime to first response, in business hours.Time to first response, in business hours.
The trigger is yours. trigger takes any element and sets a ref on it;
iconTrigger wraps an icon in a div first. The arrow does the pointing, and
hideArrow removes it — after which position is all the reader has.
portal decides where the overlay is rendered. It defaults to rendering in a
portal at the end of the document, which is what keeps a tooltip from being
clipped; set it to false inside a Modal or anything else
that establishes its own stacking context, and use zIndex where the tooltip
comes out under something.
When to use
Section titled “When to use”Use a tooltip for something the reader can do without: what an icon button means, what an abbreviation stands for, what a truncated cell says in full. Underline the word where the trigger is a term in running text, since a phrase with no affordance is a tooltip nobody finds.
Tooltips work because they are rare. A screen full of them is a screen nobody hovers, and the one that mattered is indistinguishable from the twelve that repeated the label.
A hover-only tooltip never opens on a touch screen
Section titled “A hover-only tooltip never opens on a touch screen”A tooltip is information the reader can miss, and on a touch screen there is no hover, so a tooltip that only opens that way never opens. Instructions needed to finish a task go in the interface: helper text under the field for a form, a Modal for guidance long enough to need its own focus.
disabled stops the tooltip rendering at all, which is the honest way to turn
one off in a context that cannot show it.
Behavior
Section titled “Behavior”Tooltips open below the trigger, after a pause
Section titled “Tooltips open below the trigger, after a pause”It opens 300ms after the pointer arrives, 8px below the trigger. side moves
it, and the delay is delayDuration. The pause is what stops a tooltip firing
on every element the pointer crosses on its way somewhere else; shortening it
to zero on a dense toolbar turns the whole row into flicker.
A tooltip with no renderable children renders nothing — no empty surface, no arrow. The trigger is left as it was.
Nothing in a tooltip can be operated
Section titled “Nothing in a tooltip can be operated”The pointer can enter a tooltip; nothing in it can be used. Content with
role="tooltip" is not reachable by keyboard, so a button or a link in there
cannot be operated at all — not by a keyboard, and not by anyone using the
tooltip the way it announces itself.
interactive defaults to true, which keeps the tooltip open while the pointer
is inside it. That is so a long message can be read, not permission to put
controls there — the default permits what the guidance forbids, and it is an
open question with persona-web.
Accessibility
Section titled “Accessibility”Make your own trigger focusable
Section titled “Make your own trigger focusable”trigger gets a ref and nothing else: if the element you pass is not
focusable on its own, the tooltip has no keyboard path in, and a reader who does
not use a pointer never sees it. A <button> or a link is fine. A <span> or a
bare <svg> is not.
iconTrigger is the exception, and it is why the prop exists. It wraps the icon
in a focusable div, hides the icon itself from assistive tech, and takes the
tooltip’s aria-label as the name for the wrapper — so an icon trigger is
reachable and named, where a raw icon passed to trigger is neither.
The description wiring is not yours to do. While the tooltip is open, the
trigger carries an aria-describedby pointing at the message, and the message
is also rendered in a hidden node so it reaches a screen reader whichever way
the reader arrives.
Content
Section titled “Content”Write one sentence
Section titled “Write one sentence”The surface caps at 250px wide unless maxWidth says otherwise, and it grows
downward from there. A paragraph in a tooltip becomes a tall block hanging over
the thing it was explaining, and the reader loses the element while reading
about it.
size is sm or md, defaulting to md, and it changes the tooltip’s own
type scale rather than how much it can hold. Neither size makes room for a
second sentence.
Say what the element does rather than that it can be clicked. See Writing for the rest.
| Name | Type |
|---|---|
trigger |
Element that will trigger the tooltip. A |
iconTrigger |
Icon that will trigger the tooltip. A wrapper div will be set. |
className |
|
contentAlignment |
|
hideArrow |
Optionally hide tooltip arrow. |
children |
|
disabled |
Disabling will prevent tooltip from rendering on the trigger |
portal |
Render in a portal. Disable to render adjacent to trigger for rendering within elements such as modals |
portalProps |
Props applied to Radix UI Portal component |
interactive |
Determines if the tooltip closes when the mouse hovers into the tooltip content area |
zIndex |
Override the zIndex in case the tooltip is used in situations where the content is already elevated |
maxWidth |
Max width of the contents in the tooltip |
triggerProps |
Props to apply to Tooltip.Trigger within |
size |
Size of the tooltip. Defaults to ‘md’. |
Omit<TooltipPrimitive.TooltipProps, ‘disableHoverableContent’> and TooltipPrimitive.TooltipContentProps.Was this page helpful?