Tooltip
Tooltips add additional context to interactive UI elements and appear on mouse hover or keyboard focus.
Page navigation navigation
Tooltip content is easily missed as there is no indication that a Tooltip is available until a user directly interacts with a control. Tooltips are not accessible for touch screen users as they are only seen as the element that triggers it is being pressed. Tooltips are not always available to screen reader users such as when navigating with the arrows keys in browse mode.
It is not recommended to use a Tooltip if there is another, more accessible way to convey the information. Consider alternatives to tooltips before using this component.
The primary purpose of the Tooltip component is to provide a visible label for IconButtons.
Accessibility and usability expectations
Presentation
Cognition
- For the Label variant, the label should be concise and descriptive of the purpose of the control
- For the Description variant, the description should be concise and must not include any essential content, as not all users will be able to access the content
Vision
- A
Tooltipmust be positioned next to the element that triggers it, so that it is visually obvious which element it is associated with - The
Tooltiptext and boundary must have sufficient color contrast against the background - The text in a
Tooltipmust remain readable and not require horizontal scrolling when resized or zoomed to 400% or viewed on a viewport of 320px - When the element that triggers a
Tooltiphas focus, it must have a visible focus indicator. If the indicator is custom and relies on color alone, it must meet a minimum contrast ratio of 3:1 against the background
Mobility
- A
Tooltipmust be operable with a keyboard alone, without requiring the use of a mouse or other pointing device
Adaptability
- The text in a
Tooltipmust remain readable and not require horizontal scrolling, at a viewport size of 320 by 256 CSS pixels
Interaction
Keyboard
- When activated by an element receiving focus, the
Tooltipmust remain visible while the element has focus - The
Tooltipmust close when theEsckey is pressed or focus is moved away from the trigger element
Pointer device
- When activated with the cursor, the
Tooltipmust remain visible while the cursor is over theTooltipor the triggering element, and close when the cursor moves away
Engineering for AT Compatibility
Screen reader
- The label variant of the
Tooltipuses hidden text associated with the control usingaria-labelledby, providing the accessible name for the control - The label variant must not be used on controls that already have a permanently visible label
- The description variant uses hidden text associated using
aria-describedby, providing the accessible description - The
Tooltipcomponent’s primary purpose is to provide a visible label forIconButtons
Built-in accessibility features
- The component handles all aspects of hover and keyboard interaction, and ensures that the content is readable when resized and zoomed
- The
Tooltipcan be dismissed withEscwithout moving the focus or pointer away from the trigger element - The
Tooltiptext and boundary meets minimum color contrast requirements - The content is conveyed to screen readers by use of the accessible name of the trigger control for the label variant, and the accessible description for the description variant
Implementation requirements
- Reserve
Tooltipto visually surface the label forIconButtons - Never include a
Tooltipon non-interactive components (<div>,<span>,<p>) because it will not be accessible for keyboard or screen reader users - A
Tooltipis not allowed on disabled elements because such elements are not keyboard-accessible. If you must set aTooltipon a disabled element, usearia-disabled="true"instead and programmatically disable the element - A
Tooltipshould only hold string content, as structural information is not available to screen readers via the accessible name and accessible description
How to test the component
Integration tests
- A
Tooltiponly appear on interactive elements - A
Tooltipdoes not appear on disabled elements, but can appear on inactive elements - When the element that triggers a
Tooltiphas focus, it has a focus indicator that meets color contrast requirements - The
Tooltipcontains only string content - A label
Tooltipis not used on controls that have a visible label - For a label
Tooltip, the label is concise and descriptive of the purpose of the control - For a description
Tooltip, the description is concise and contains only non-essential text
Component tests
- The
Tooltipappears next to the trigger control when the control is hovered or focused - The
Tooltipremains visible whilst the cursor is over the Tooltip and the interactive control, and closes when the cursor is moved away - The
Tooltipremains visible whilst the trigger control has focus and closes when theEsckey is activated and when focus is moved away from the trigger control - The
Tooltiptext has sufficient contrast, at least 4.5:1, against the background - The
Tooltiptext can be resized to 200% and remain readable - When viewed at 400% or on a 320px viewport, the
Tooltiptext remain readable and does not require horizontal scrolling - In the label variant, the
Tooltiptext is associated with the control witharia-labelledbyand hidden from the accessibility tree witharia-hidden="true" - In the description variant, the
Tooltiptext is associated with the control witharia-describedbyand hidden from the accessibility tree witharia-hidden="true"