Tooltip

Tooltips add additional context to interactive UI elements and appear on mouse hover or keyboard focus.

⚠️ Usage Warning ⚠️Tooltips as a UI pattern should be the last resort for conveying information as they are hidden by default and often with zero or little visual indicator of its existence. See tooltip alternatives before using this component.

Usage

Three examples of tooltips on interactive elements
  • Reserve tooltips to visually surface the label for icon buttons.
  • Keep the tooltip text minimal.
  • Never include tooltips on non-interactive components (div, span, p) because it will not be accessible for keyboard or screen reader users.

Best practices

Do
Icon buttons with tooltips for edit, favorite, and sponsor

Use a tooltip on an icon button to help convey the purpose of the action

Don’t
Non-interactive text element activating a long and wordy tooltip on hover

Don't use tooltips on non-interactive elements

Options

Label

icon button with tooltip as a label

Icon buttons have a visually hidden label utilizing `aria-label`. To instead display that label in a tooltip, the `label` option should be used. The `label` serves as the accessible name for the control utilitizing `aria-labelledby` under the hood.

Description

The description is intended to supplement the control's text label by utilitizing aria-describedby under the hood, and will be announced to a screen reader in addition to the label. Keep the description short and concise.

Icon button with visually hidden label

Icon button with tooltip as a description

Icon buttons have a visually hidden label utilizing `aria-label`. To provide context in addition to the visually hidden label, use the `description` option.

Button with visible label

Button labeled Notifications with tooltip as a description

For buttons that have a visible label, the `description` option can also be used to provide additional context.

Position

By default, the Tooltip component will position itself below the interactive control in a centered alignment. The position is dependant on the space available within the viewport, and it will never break outside of it. It may appear to the top, bottom, left, or right of the interactive control.

tooltips rendered in all possible positions surrounding a control

Alternatives to tooltips

Before adding a tooltip, please consider: Is this information essential and necessary? Can the UI be made clearer? Can the information be shown on the page by default? See Tooltip alternatives for more accessible alternatives.

We use aria-label for tooltip contents. However, aria-label replaces the text content of an element in screen readers, so only use Tooltip on elements with no existing text content.

A tooltip may only be used on an element that is interactive such as a button or a link. Even if an element is focusable, a tooltip may only be used if the element does something when it's clicked.

1. Persist the content

If possible, persist the content so it's always available rather than using a tooltip, which hides content by default. This ensures that the content is always discovered and surfaced to users regardless of device.

Do
Information about how many discussions can be pinned added to the confirmation dialog

Find an appropriate permanent place to display additional information.

Don’t
Information about how many discussions can be pinned within tooltip on non-interactive element

Don't use a tooltip to add additional helpful information

2. Don't duplicate content

If the tooltip duplicates content that is already available on the page, remove it.

Do
Pointer hovering over a link with no tooltip

Remove any duplicate tooltip text.

Don’t
Screenshot of tooltip with GitHub username, @inkblotty, on a static span that says @inkblotty

Don't set tooltips that duplicate the trigger element content.

3. Use a modal

Consider using a modal, which is accessible for mobile users and allows you to structure content that may otherwise be crammed into a tooltip.

Do
Screenshot of GitHub Actions page with a modal that conveys workflow file information about a runner

Do use a pattern that is accessible to a larger number of users such as a modal

Don’t
Screenshot of GitHub Actions page using a tooltip on a static element to convey long workflow file information

Don't place long content inside a tooltip

4. Use a summary disclosure

Consider using a summary disclosure that is accessible for mobile users and also offers the ability to show or hide content.

Do
Screenshot of GitHub pricing page that uses a summary disclosure to hide and show additional information on each point

Do use a pattern that is accessible to a larger number of users such as a summary disclosure

Don’t
Screenshot of GitHub pricing page using a tooltip to hide and show long descriptions on each point

Don't use tooltips on non-interactive elements

Other

If you are unsure which alternative is more suited to your scenario and need help, consult a designer or the GitHub Accessibility team (if you are GitHub staff) for advice.

Additional resources

Known accessibility issues

View open accessibility issues related to this component