Search
MaterialComponentsDocs
Components overviewApp barBadgeButtonsButton groupButtonExtended FABFAB menuFABIcon buttonSplit buttonCardCarouselCheckboxChipsDate & time pickersDate pickerTime pickerDialogDividerListLoading & progressLoading indicatorProgressMenuNavigationNavigation barNavigation drawerNavigation railRadio buttonsSearchSelectSheetsBottom sheetSide sheetSliderSnackbarSwitchTabsText fieldToolbarTooltip

Tooltip

Add a little context. Hover or focus the action to explore tooltip styles, placement, and timing.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A tooltip is a short label for another element, shown on hover and on focus: it names an icon button, or says what a control does, in a few words. It holds nothing to act on.

Usage

The tooltip describes its target: 300ms after the pointer enters it or it takes focus, the tooltip shows, below it by default. The web component's target is the element its for attribute names.

Vanilla
import { createTooltip, createIconButton } from 'material';

const trigger = createIconButton({ icon: heartOutlineIcon, ariaLabel: 'Favorite' });
document.body.append(trigger.element);

const tooltip = createTooltip({ target: trigger.element, text: 'Add to favorites' });
document.body.append(tooltip.element);
Web Components
<m-icon-button id="tooltip-target" aria-label="Favorite"></m-icon-button>
<m-tooltip text="Add to favorites" for="tooltip-target"></m-tooltip>

<script type="module">
  document.querySelector('#tooltip-target').setAttribute('icon', heartOutlineIcon);
</script>
React
import { Tooltip, IconButton } from 'material/react';
import { heartOutlineIcon } from './app';

export function Example() {
  return (
    <>
      <IconButton id="tooltip-target" icon={heartOutlineIcon} ariaLabel="Favorite" />
      <Tooltip text="Add to favorites" for="tooltip-target" />
    </>
  );
}
Vue
<script setup lang="ts">
import { MTooltip, MIconButton } from 'material/vue';
import { heartOutlineIcon } from './app';
</script>

<template>
  <MIconButton id="tooltip-target" :icon="heartOutlineIcon" aria-label="Favorite" />
  <MTooltip text="Add to favorites" for="tooltip-target" />
</template>
Svelte
<script lang="ts">
  import { Tooltip, IconButton } from 'material/svelte';
  import { heartOutlineIcon } from './app';
</script>

<IconButton id="tooltip-target" icon={heartOutlineIcon} ariaLabel="Favorite" />
<Tooltip text="Add to favorites" for="tooltip-target" />
SolidJS
import { Tooltip, IconButton } from 'material/solid';
import { heartOutlineIcon } from './app';

export function Example() {
  return (
    <>
      <IconButton id="tooltip-target" icon={heartOutlineIcon} ariaLabel="Favorite" />
      <Tooltip text="Add to favorites" for="tooltip-target" />
    </>
  );
}

Examples

Position

position is top, right, bottom or left, each also with -start or -end to align it with an edge of the target. It is kept inside the window's width.

Vanilla
import { createTooltip, createIconButton } from 'material';

const trigger = createIconButton({ icon: shareIcon, ariaLabel: 'Share' });
document.body.append(trigger.element);

const tooltip = createTooltip({ target: trigger.element, text: 'Share', position: 'top' });
document.body.append(tooltip.element);
Web Components
<m-icon-button id="tooltip-target" aria-label="Share"></m-icon-button>
<m-tooltip text="Share" position="top" for="tooltip-target"></m-tooltip>

<script type="module">
  document.querySelector('#tooltip-target').setAttribute('icon', shareIcon);
</script>
React
import { Tooltip, IconButton } from 'material/react';
import { shareIcon } from './app';

export function Example() {
  return (
    <>
      <IconButton id="tooltip-target" icon={shareIcon} ariaLabel="Share" />
      <Tooltip text="Share" position="top" for="tooltip-target" />
    </>
  );
}
Vue
<script setup lang="ts">
import { MTooltip, MIconButton } from 'material/vue';
import { shareIcon } from './app';
</script>

<template>
  <MIconButton id="tooltip-target" :icon="shareIcon" aria-label="Share" />
  <MTooltip text="Share" position="top" for="tooltip-target" />
</template>
Svelte
<script lang="ts">
  import { Tooltip, IconButton } from 'material/svelte';
  import { shareIcon } from './app';
</script>

<IconButton id="tooltip-target" icon={shareIcon} ariaLabel="Share" />
<Tooltip text="Share" position="top" for="tooltip-target" />
SolidJS
import { Tooltip, IconButton } from 'material/solid';
import { shareIcon } from './app';

export function Example() {
  return (
    <>
      <IconButton id="tooltip-target" icon={shareIcon} ariaLabel="Share" />
      <Tooltip text="Share" position="top" for="tooltip-target" />
    </>
  );
}

Timing and triggers

showDelay and hideDelay are in milliseconds. showOnHover: false leaves it to focus, and showOnFocus: false to the pointer; show() and hide() drive it from script.

Vanilla
import { createTooltip, createIconButton } from 'material';

const trigger = createIconButton({ icon: settingsIcon, ariaLabel: 'Settings' });
document.body.append(trigger.element);

const tooltip = createTooltip({
  target: trigger.element,
  text: 'Settings',
  showDelay: 600,
  hideDelay: 0,
  showOnHover: false,
});
document.body.append(tooltip.element);
Web Components
<m-icon-button id="tooltip-target" aria-label="Settings"></m-icon-button>
<m-tooltip text="Settings" show-delay="600" hide-delay="0" no-show-on-hover for="tooltip-target"></m-tooltip>

<script type="module">
  document.querySelector('#tooltip-target').setAttribute('icon', settingsIcon);
</script>
React
import { Tooltip, IconButton } from 'material/react';
import { settingsIcon } from './app';

export function Example() {
  return (
    <>
      <IconButton id="tooltip-target" icon={settingsIcon} ariaLabel="Settings" />
      <Tooltip text="Settings" showDelay={600} hideDelay={0} noShowOnHover for="tooltip-target" />
    </>
  );
}
Vue
<script setup lang="ts">
import { MTooltip, MIconButton } from 'material/vue';
import { settingsIcon } from './app';
</script>

<template>
  <MIconButton id="tooltip-target" :icon="settingsIcon" aria-label="Settings" />
  <MTooltip text="Settings" :show-delay="600" :hide-delay="0" no-show-on-hover for="tooltip-target" />
</template>
Svelte
<script lang="ts">
  import { Tooltip, IconButton } from 'material/svelte';
  import { settingsIcon } from './app';
</script>

<IconButton id="tooltip-target" icon={settingsIcon} ariaLabel="Settings" />
<Tooltip text="Settings" showDelay={600} hideDelay={0} noShowOnHover for="tooltip-target" />
SolidJS
import { Tooltip, IconButton } from 'material/solid';
import { settingsIcon } from './app';

export function Example() {
  return (
    <>
      <IconButton id="tooltip-target" icon={settingsIcon} ariaLabel="Settings" />
      <Tooltip text="Settings" showDelay={600} hideDelay={0} noShowOnHover for="tooltip-target" />
    </>
  );
}

setTarget() moves a tooltip to another element, so one tooltip can serve a list. layer: 'top' shows it in the browser's top layer, above any clipping or stacking; the web component always is. When a tooltip's target opens a menu, pressing the target or pressing Enter or Space hides the tooltip at once; it stays hidden while the target's menu is open and returns only on a hover or focus after the menu closes.

API

Options

text

The label

Typestring
Defaultundefined
target

The element it describes

TypeHTMLElement
Defaultundefined
position

Where it sits against the target

TypeTooltipPosition
Default'bottom'
variant

default and plain are M3's plain tooltip, on inverse-surface; rich is M3's rich tooltip, on surface-container

Type'default' | 'plain' | 'rich'
Default'default'
visible

Whether it shows at once

Typeboolean
Defaultfalse
showDelay / hideDelay

How long before it shows or hides, in ms

Typenumber
Default300 / 100
showOnHover / showOnFocus

Whether the pointer, and focus, show it

Typeboolean
Defaulttrue
layer

Shows it in the top layer, after its target in the target's tree

Type'top'
Defaultundefined
zIndex

Its z-index, outside the top layer

Typenumber
Defaultundefined
class

Additional CSS classes

Typestring
Defaultundefined
prefix

Prefix for CSS class names

Typestring
Default'mtrl'

The web component takes for, text (or its own text), position, variant, show-delay, hide-delay, no-show-on-hover and no-show-on-focus, and a target property that wins over for.

Methods

show(immediate?) / hide(immediate?)

Shows or hides it, at once when immediate

Parametersimmediate?: boolean
ReturnsTooltipComponent
isVisible()

Whether it is shown

Parametersnone
Returnsboolean
getText() / setText(text)

The label

Parameterstext: string
Returnsstring / TooltipComponent
getPosition() / setPosition(position)

Where it sits

Parametersposition: TooltipPosition
Returnsstring / TooltipComponent
setTarget(target)

Describes another element

Parameterstarget: HTMLElement
ReturnsTooltipComponent
updatePosition()

Places it again against its target

Parametersnone
ReturnsTooltipComponent
destroy()

Releases its target and removes it

Parametersnone
Returnsvoid
element

The tooltip

TypeHTMLElement
target

The element it describes

TypeHTMLElement | null

A tooltip has no events.

Styling

.mtrl-tooltip, .mtrl-tooltip--visible { }
.mtrl-tooltip--default, .mtrl-tooltip--plain, .mtrl-tooltip--rich { }
.mtrl-tooltip--top, .mtrl-tooltip--bottom { }
.mtrl-tooltip__arrow { }

Measurements

Attribute Value
Container inverse-surface, opaque, no elevation, 4dp corners, 200dp wide at most
Text Body Small, inverse-on-surface
Padding 4dp above and below, 8dp at the sides
Rich surface-container, 12dp corners, elevation 2, 320dp wide at most; Body Medium, on-surface-variant; 12dp above and below, 16dp at the sides
Distance from the target 8dp