Skip to content

Material 3

Components

Tooltip

Tooltips display brief labels or messages.

9:30

Summer trip

Favorite
Share this albumInvite friends and family to this album. People you invite can add their own photos.

Tooltips display brief labels or messages. Use them to add context to a button or another element while it is hovered or focused. A tooltip should not hold information that people cannot do without.

For information that people need, show it on the page, or in a dialog when it needs a response.

A tooltip is written with these parts:

PartUse
TooltipTriggerWraps the element to describe and a Tooltip, with the element first. It opens the tooltip on a hover or keyboard focus.
TooltipA plain tooltip (the default) or, with variant="rich", a rich tooltip
PreviewTriggerWraps an element and a TooltipPopover, for a rich tooltip with actions
TooltipPopoverA rich tooltip with buttons or links, in a PreviewTrigger, or in a DialogTrigger for a persistent rich tooltip
import { PreviewTrigger, Tooltip, TooltipPopover, TooltipTrigger } from '@material-web/react'
import { Dialog, DialogTrigger, Focusable, Heading, Text } from 'react-aria-components'

Basic tooltip

Wrap the element to describe and a Tooltip in a TooltipTrigger, the element first. Hover a button below, or move the focus to it with Tab.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

const actions = [
  ['Add to favorites', 'star'],
  ['Share', 'share'],
  ['Download', 'download'],
  ['Delete', 'delete'],
] as const

export default function Basic() {
  return (
    <>
      {actions.map(([label, icon]) => (
        <TooltipTrigger key={label}>
          <IconButton aria-label={label}>
            <Icon name={icon} />
          </IconButton>
          <Tooltip>{label}</Tooltip>
        </TooltipTrigger>
      ))}
    </>
  )
}

The Tooltip comes in two variants: plain (the default) and rich. Set variant to choose one.

Plain tooltip

A plain tooltip briefly describes an element. Use it to label an element with no text, such as an icon button. Write a plain tooltip's text as its children. Text wider than 200dp wraps onto more lines.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

export default function MultiLine() {
  return (
    <TooltipTrigger>
      <IconButton aria-label="Grant value">
        <Icon name="info" />
      </IconButton>
      <Tooltip>
        Grant value is calculated using the closing stock price from the day before the grant date.
      </Tooltip>
    </TooltipTrigger>
  )
}

Rich tooltip

A rich tooltip gives more context about an element. Use it for longer text, such as a definition or an explanation.

Set variant="rich" for a tooltip with a subhead and supporting text. Write the subhead as a Heading, and the supporting text after it. A rich tooltip is up to 320dp wide, and is placed below its element, centered and 4dp away. Set placement to move it.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
import { Heading } from 'react-aria-components'

export default function Rich() {
  return (
    <TooltipTrigger>
      <IconButton aria-label="Favorite">
        <Icon name="star" />
      </IconButton>
      <Tooltip variant="rich">
        <Heading>Favorite</Heading>
        Find this later in your favorites.
      </Tooltip>
    </TooltipTrigger>
  )
}

Use a Tooltip for a rich tooltip with no buttons or links. The keyboard cannot reach what is inside a Tooltip: for one with buttons or links, see Rich tooltips with actions.

Rich tooltips with actions

For a rich tooltip with buttons or links, put a TooltipPopover in a PreviewTrigger, after the element. Write the subhead as a Heading, then the supporting text, then the buttons as Buttons with variant="text". The buttons are placed side by side below the text: use up to two, with short labels.

Note: Put the supporting text in a Text when the tooltip has buttons or the text holds a link. Text written without one shares the buttons' row.

In a PreviewTrigger, the TooltipPopover opens 0.6s into a hover or keyboard focus, or on a long press on a touch screen. Set delay to change the 0.6s.

  • The pointer can move onto the popover and stay over it.
  • Tab from the element moves the focus into the popover, through its links and buttons from top to bottom, and then on to the element after the trigger.
  • The popover closes 1.5s after the pointer has left both it and its element and the focus has gone.
  • Escape closes it at once from its element, and after the close delay from inside the popover. Set a shorter closeDelay to shorten both.
import { Button, Icon, IconButton, PreviewTrigger, TooltipPopover } from '@material-web/react'
import { Heading, Text } from 'react-aria-components'

export default function RichActions() {
  return (
    <>
      <PreviewTrigger>
        <IconButton aria-label="Add others">
          <Icon name="person_add" />
        </IconButton>
        <TooltipPopover>
          <Heading>Add others</Heading>
          <Text>Share this collection with friends and family.</Text>
          <Button variant="text">Learn more</Button>
          <Button variant="text">Share</Button>
        </TooltipPopover>
      </PreviewTrigger>
      <IconButton aria-label="Next">
        <Icon name="arrow_forward" className="rtl:icon-mirrored" />
      </IconButton>
    </>
  )
}

Persistent rich tooltips

For a rich tooltip that opens on a press and not on a hover, put a TooltipPopover in a DialogTrigger, after the element. Avoid a persistent rich tooltip on an icon button.

Set isNonModal on the TooltipPopover and put a Dialog from react-aria-components in it. Name the dialog with a Heading with slot="title". The tooltip then behaves as follows:

  • It stays open when the pointer leaves.
  • It closes on a press of another element, which also receives the press.
  • It closes on Escape, and the focus returns to its element.
  • A Button with slot="close" inside it closes it too.
  • Tab stays inside it while it is open.

Without isNonModal, the popover is modal: the page behind it is hidden from assistive technology, the focus stays in the popover, and a press outside only closes it.

import { Button, TooltipPopover } from '@material-web/react'
import { Dialog, DialogTrigger, Heading, Text } from 'react-aria-components'

export default function Persistent() {
  return (
    <>
      <DialogTrigger>
        <Button variant="outlined">Image quality</Button>
        <TooltipPopover isNonModal>
          <Dialog>
            <Heading slot="title">New settings available</Heading>
            <Text>Now you can adjust the uploaded image quality.</Text>
            <Button variant="text" slot="close">
              Got it
            </Button>
          </Dialog>
        </TooltipPopover>
      </DialogTrigger>
      <Button variant="text">Storage</Button>
    </>
  )
}

To show a tooltip as the page loads, render a TooltipPopover with isOpen and a triggerRef, without a trigger. It is placed by the element of the ref, as with React Aria's custom anchor. Close it in onOpenChange, which is called on Escape and on a press of another element. A button inside it closes it in its onPress.

function NewSettings() {
  const settings = useRef<HTMLButtonElement>(null)
  const [isOpen, setOpen] = useState(true)
  return (
    <>
      <IconButton ref={settings} aria-label="Settings">
        <Icon name="settings" />
      </IconButton>
      <TooltipPopover triggerRef={settings} isOpen={isOpen} onOpenChange={setOpen} isNonModal>
        <Dialog>
          <Heading slot="title">New settings available</Heading>
          <Text>Now you can adjust the uploaded image quality.</Text>
          <Button variant="text" onPress={() => setOpen(false)}>
            Got it
          </Button>
        </Dialog>
      </TooltipPopover>
    </>
  )
}

Labels and descriptions

A tooltip describes its element and does not name it. While the tooltip is open, the element refers to it with aria-describedby. An element with no visible text, such as an IconButton, still needs an aria-label, even when the tooltip shows the same text.

<TooltipTrigger>
  <IconButton aria-label="Delete">
    <Icon name="delete" />
  </IconButton>
  <Tooltip>Delete</Tooltip>
</TooltipTrigger>

Triggers

A trigger decides what opens its tooltip:

TriggerHoldsOpens on
TooltipTriggerA TooltipA hover or keyboard focus
PreviewTriggerA TooltipPopoverA hover or keyboard focus, or a long press on a touch screen
DialogTriggerA TooltipPopoverA press

Set trigger="focus" on a TooltipTrigger to open its tooltip on focus only.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

export default function Triggers() {
  return (
    <>
      <TooltipTrigger>
        <IconButton aria-label="Undo">
          <Icon name="undo" className="rtl:icon-mirrored" />
        </IconButton>
        <Tooltip>Undo, on hover or focus</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger trigger="focus">
        <IconButton aria-label="Redo">
          <Icon name="redo" className="rtl:icon-mirrored" />
        </IconButton>
        <Tooltip>Redo, on focus alone</Tooltip>
      </TooltipTrigger>
    </>
  )
}

For a TooltipPopover in a PreviewTrigger, see Rich tooltips with actions. For one in a DialogTrigger, see Persistent rich tooltips.

Custom trigger element

The element of a TooltipTrigger can be a Button, an IconButton, a Fab or any other focusable React Aria component.

To describe another element, such as an element of your own or a third-party component, wrap it in React Aria's Focusable. The element must be able to take the focus, so give one that is not a native control a tabIndex and a role.

import { Button, Fab, Icon, Tooltip, TooltipTrigger } from '@material-web/react'
import { Focusable } from 'react-aria-components'

export default function Elements() {
  return (
    <>
      <TooltipTrigger>
        <Button variant="tonal">Publish</Button>
        <Tooltip>Publish to everyone</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <Fab aria-label="Compose">
          <Icon name="edit" />
        </Fab>
        <Tooltip>Compose</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <Focusable>
          <span
            role="img"
            aria-label="Verified"
            tabIndex={0}
            className="focus-ring flex rounded-shape-full text-primary icon-24"
          >
            <Icon name="verified" />
          </span>
        </Focusable>
        <Tooltip>This account is verified</Tooltip>
      </TooltipTrigger>
    </>
  )
}

Controlled

Control the open state with isOpen and onOpenChange on the TooltipTrigger, or set the initial state with defaultOpen. onOpenChange is called when the tooltip would open or close.

The tooltip is closed
import { Button, Tooltip, TooltipTrigger } from '@material-web/react'
import { useState } from 'react'

export default function Controlled() {
  const [isOpen, setOpen] = useState(false)
  return (
    <>
      <TooltipTrigger isOpen={isOpen} onOpenChange={setOpen}>
        <Button variant="outlined">Sync</Button>
        <Tooltip>Sync your files now</Tooltip>
      </TooltipTrigger>
      <span className="text-body-md text-on-surface-variant">
        The tooltip is {isOpen ? 'open' : 'closed'}
      </span>
    </>
  )
}

A PreviewTrigger and a DialogTrigger take the same three props.

Opening and closing

A tooltip closes 1.5s after the pointer leaves. Set closeDelay on the TooltipTrigger or the PreviewTrigger to change this. Both delays are in milliseconds.

In a TooltipTrigger:

  • A hover opens the tooltip after 0.5s, and keyboard focus opens it at once. Set delay to change the 0.5s.
  • The tooltip closes at once when the focus leaves, on Escape, and on a press of its element, which shouldCloseOnPress controls.
  • The tooltip stays open while the pointer is on it.
  • One tooltip shows at a time. Once one has opened, hovering another element opens its tooltip at once and closes the first.

Note: A touch opens no tooltip, and a disabled element has none. The pointer's first move in a page opens none either, if it lands on a trigger.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

export default function Delay() {
  return (
    <>
      <TooltipTrigger delay={0} closeDelay={0}>
        <IconButton aria-label="Undo">
          <Icon name="undo" className="rtl:icon-mirrored" />
        </IconButton>
        <Tooltip>Undo, at once</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger delay={1000} closeDelay={3000}>
        <IconButton aria-label="Redo">
          <Icon name="redo" className="rtl:icon-mirrored" />
        </IconButton>
        <Tooltip>Redo, after a second</Tooltip>
      </TooltipTrigger>
    </>
  )
}

Disabled

A disabled element shows no tooltip: it cannot be focused and reports no hover.

To turn a tooltip off while its element stays enabled, set isDisabled on the TooltipTrigger.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

export default function Disabled() {
  return (
    <>
      <TooltipTrigger isDisabled>
        <IconButton aria-label="Share">
          <Icon name="share" />
        </IconButton>
        <Tooltip>Share</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <IconButton aria-label="Delete" isDisabled>
          <Icon name="delete" />
        </IconButton>
        <Tooltip>Delete</Tooltip>
      </TooltipTrigger>
    </>
  )
}

Widths

A tooltip wraps text wider than its maximum width: 200dp for a plain tooltip, and 320dp for a rich one. To change it, set a max-w-* class on the Tooltip.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
import { Heading } from 'react-aria-components'

export default function Width() {
  return (
    <>
      <TooltipTrigger>
        <IconButton aria-label="Grant value">
          <Icon name="info" />
        </IconButton>
        <Tooltip className="max-w-80">
          Grant value is calculated using the closing stock price from the day before the grant
          date.
        </Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <IconButton aria-label="Favorite">
          <Icon name="star" />
        </IconButton>
        <Tooltip variant="rich" className="max-w-50">
          <Heading>Favorite</Heading>
          Find this later in your favorites.
        </Tooltip>
      </TooltipTrigger>
    </>
  )
}

Placement

A plain tooltip is placed above its element, centered and 4dp away. Set placement on the Tooltip to the side of the element the tooltip is on, one of React Aria's placements. A second word aligns the tooltip with an edge of the element, as in top start or bottom end.

The tooltip flips to the other side where the window has no room.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

const placements = [
  ['top', 'arrow_upward'],
  ['bottom', 'arrow_downward'],
  ['left', 'arrow_back'],
  ['right', 'arrow_forward'],
] as const

export default function Placement() {
  return (
    <>
      {placements.map(([placement, icon]) => (
        <TooltipTrigger key={placement}>
          <IconButton variant="tonal" aria-label={placement}>
            <Icon name={icon} />
          </IconButton>
          <Tooltip placement={placement}>{placement}</Tooltip>
        </TooltipTrigger>
      ))}
    </>
  )
}

In an app bar, set placement="bottom" to place the tooltip below its element.

Photos

import { AppBar, Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
import { Heading } from 'react-aria-components'

const actions = [
  ['Add to favorites', 'star'],
  ['Share', 'share'],
  ['Download', 'download'],
] as const

export default function InAppBar() {
  return (
    <div className="h-40 w-full">
      <AppBar>
        <Heading slot="headline" level={2}>
          Photos
        </Heading>
        {actions.map(([label, icon]) => (
          <TooltipTrigger key={label}>
            <IconButton slot="trailing" aria-label={label}>
              <Icon name={icon} />
            </IconButton>
            <Tooltip placement="bottom">{label}</Tooltip>
          </TooltipTrigger>
        ))}
      </AppBar>
    </div>
  )
}

Distance from element

Set offset on the Tooltip to the distance from the element: 4dp by default. Use offset={8} for an element with no visual boundary, such as text.

import { Button, Tooltip, TooltipTrigger } from '@material-web/react'

export default function Offset() {
  return (
    <>
      <TooltipTrigger>
        <Button variant="outlined">Default</Button>
        <Tooltip>4dp away</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <Button variant="text">Text</Button>
        <Tooltip offset={8}>8dp away</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <Button variant="outlined">Farther</Button>
        <Tooltip offset={16}>16dp away</Tooltip>
      </TooltipTrigger>
    </>
  )
}
  • crossOffset moves the tooltip along the side of the element it is on.
  • containerPadding is the distance the tooltip keeps from the window's edges: 8dp (the default).

Customization

Pass classes in className to restyle one tooltip. A class of yours replaces the tooltip's own class for the same property. See Styling for the classes, the states and the theme.

import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'

export default function Custom() {
  return (
    <>
      <TooltipTrigger>
        <IconButton aria-label="Delete">
          <Icon name="delete" />
        </IconButton>
        <Tooltip className="bg-error text-on-error">Delete</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <IconButton aria-label="Share">
          <Icon name="share" />
        </IconButton>
        <Tooltip className="rounded-shape-full px-space-150">Share</Tooltip>
      </TooltipTrigger>
      <TooltipTrigger>
        <IconButton aria-label="Download">
          <Icon name="download" />
        </IconButton>
        <Tooltip data-theme="dark" variant="rich">
          Saved to your downloads folder.
        </Tooltip>
      </TooltipTrigger>
    </>
  )
}
  • Color: To use other color roles, pass a container color and the on-color of that container, as in bg-error text-on-error.
  • Functions: className, style and the children can be functions of the tooltip's state. See Children as a function.
  • Ancestors: A tooltip is rendered at the end of the page, not inside the element it is written in. A class or a data-theme on an element around its trigger does not reach it. Set it on the Tooltip or the TooltipPopover itself, or on the root element.
  • Every tooltip: To restyle all the tooltips at once, change the theme.