Component
Tooltip
Published on
Description
Write a plain title attribute. The bootstrap/tooltip.js script replaces each one with a popover="hint" element anchored to the element it describes, shown on hover and on focus. Without JavaScript, or without CSS anchor positioning, the browser keeps rendering its own title tooltip, so nothing is lost.
The tooltip renders above the element by default and moves below it, or toward the opposite inline edge, when the viewport runs out of room. It hides itself when the element it describes scrolls out of view.
Use it for supplemental hints that repeat or clarify. Content that a user must read to complete a task belongs in the page, not in a tooltip. For overlays with interactive content, use a Popover.
Example
Accessibility
- The
titlestays on the element, so the accessible description is unchanged. It is emptied only while the pointer is over the element, which is what stops the browser drawing its own tooltip on top. - The tooltip element is
aria-hidden. It repeats thetitlevisually and adds nothing for a screen reader to announce twice. - Tooltips open on
focusas well as hover, andabbris giventabindex="0"so keyboard users can reach its expansion. - Escape closes an open tooltip, it stays open while hovered, and it never times out, meeting WCAG 1.4.13(opens in new tab).
- A 400ms delay before showing avoids flashing tooltips while the pointer crosses the page.
References
- Tooltips in the time of WCAG 2.1(opens in new tab) — Sarah Higley
- Tooltips & Toggletips(opens in new tab) — Adrian Roselli
- CSS anchor positioning(opens in new tab) — MDN
Related
- Popover — for overlays holding interactive content
- Dialog — for modal content that blocks the page
- Inline format — for
abbrand other inline semantics
Variables
None