Rich tooltip
A rich tooltip shows a heading, a few lines of text and an optional action beside the element it describes. Left alone, it follows hover and focus; made persistent, it stays open until dismissed, which gives a reader time to use its action. Hover, focus, or press any button below to open its tooltip.
Reference docs
Choosing a pop-up surface
Five kinds of surface open over the page for a moment. Each suits a different job:
- Dialog: a question the reader must answer before going on, such as Discard unsaved changes?
- Popover: extra content opened from a control and dismissed by clicking away, such as a small settings panel.
- Menu: a short list of commands opened from a button, such as Rename, Duplicate, Delete.
- Plain tooltip: a short label shown on hover or focus, such as what an icon button does.
- Rich tooltip: a heading, a few lines of text and an optional action shown next to the element it describes, such as what a new feature does.
Three jobs belong elsewhere. A message about something that just happened is a toast, content that stays on the page is a card, and a short set of creation actions opened from a floating button is a FAB menu.
Choosing a variant
Two behaviors set how long a rich tooltip stays and who decides:
- Standard: opens on hover, focus, or a click on the anchor, and closes when the reader moves away or presses outside it; suits an explanation a reader skims, such as what a new feature does.
- Persistent: set
; opens on a click or tap on the anchor and stays until dismissed; suits text or an action a reader needs time with, such as a link to the full guide.persistent
Built in
places the tooltip against its anchor in one of eight positions.position- A short grace period keeps the tooltip open while the pointer travels from the anchor to its action.
- The
sub-headingandcontentdescribe the anchor to assistive technology. - A persistent tooltip's button anchor is announced as expanded while the tooltip is open.
points the tooltip at an element already on the page, andanchorshow()andhide()open and close it from code.- Escape and a press outside both close it.
Hidden content renders when first shown
A rich tooltip keeps its content and actions hidden until it shows. Each showing looks like the first, and your own content and actions are untouched. Wait for updateComplete and the hidden content has rendered, so your code can reach it at once. See Hidden content renders when first shown.
Using rich tooltips well
- Use a rich tooltip for extra information and actions about an element or a new feature.
- Give the sub-heading one line, and always include it when the tooltip appears on page load.
- Offer at most two short text buttons, side by side.
- Leave persistent tooltips off icon buttons.
- Put critical information in a dialog, because a tooltip is easy to miss.
- Use a plain tooltip when a short label is all the element needs.
These rules follow Material 3 Expressive's guidance for tooltips, on material.io.
Position
positionend-center
Content
A rich tooltip takes a small heading in the sub-heading slot, its text in the content slot and up to two text buttons in the action slot. The anchor goes in the default slot. A screen reader reads the sub-heading and content after the anchor's name, but not the action, so put nothing essential in the action alone.
Persistent
Set persistent
Anchors and methods
By default the tooltip wraps its anchor. Set anchorexternal-anchor
show() and hide() open and close the tooltip from script. With an anchor set by anchor
Properties
| Property | Attribute | Type | Description |
|---|---|---|---|
anchor | anchor | string | The id of the element the tooltip attaches to. The element is found in the same page or component as the tooltip, and the tooltip does not wrap it.Takes precedence over the anchorElement property.Note: an id cannot name an element inside another component. Use external-anchor with the anchorElement property for that case. See Anchors and methods. |
anchorElement | HTMLElement | The element the tooltip attaches to and positions against.Resolves in precedence order: the anchor idref, then an element assigned to this property, then the content the tooltip wraps.Assign an element, with external-anchor, to anchor to one an id cannot find, such as an element inside another component. | |
externalAnchor | external-anchor | booleandefault false | Set this when the anchor is not slotted into the tooltip: the tooltip attaches to the element anchorElement resolves to, and the default slot is ignored. See Anchors and methods. |
persistent | persistent | booleandefault false | Opens on a click or tap on a slotted anchor and stays open until dismissed, rather than following hover and focus. With anchor or external-anchor, open and close it with show() and hide(). Use it when the tooltip holds actions or text a reader needs time with. See Persistent. |
position | positionstart-start, start-center, start-end, center-start, center-end, end-start, end-center, end-end | TooltipPositionTooltipPosition.StartStart, .StartCenter, .StartEnd, .CenterStart, .CenterEnd, .EndStart, .EndCenter, .EndEnddefault TooltipPosition.EndCenter, from the style configuration | Where the tooltip sits relative to its anchor, named as the block position then the inline position: end-center is below the anchor and centered. The inline position mirrors in right-to-left text. See Position. |
Setting persistentshow() and hide() toggle a persistent tooltip.
Slots
| Slot | Description |
|---|---|
| (default) | The anchor element. Not used, and not rendered, when anchor or external-anchor supplies the anchor. |
sub-heading | A small heading above the content. |
content | The tooltip's main content, as text or elements. |
action | A button or other action the reader can take from the tooltip. |
Methods
| Method | Returns | Description |
|---|---|---|
hide() | void | Closes the tooltip. A pending hover or focus delay is canceled, and focus inside the tooltip returns to the anchor. |
show() | void | Opens the tooltip at the current anchor. A pending hover or focus delay is canceled, so this call decides. |
Props
| Prop | Type | Description |
|---|---|---|
anchor | string | The id of the element the tooltip attaches to. The element is found in the same page or component as the tooltip, and the tooltip does not wrap it.Takes precedence over the anchorElement prop.Note: an id cannot name an element inside another component. Use externalAnchor with the anchorElement prop for that case. See Anchors and methods. |
anchorElement | HTMLElement | The element the tooltip attaches to and positions against.Resolves in precedence order: the anchor idref, then an element assigned to this property, then the content the tooltip wraps.Assign an element, with externalAnchor, to anchor to one an id cannot find, such as an element inside another component. |
externalAnchor | booleandefault false | Set this when the anchor is not slotted into the tooltip: the tooltip attaches to the element anchorElement resolves to, and the default slot is ignored. See Anchors and methods. |
persistent | booleandefault false | Opens on a click or tap on a slotted anchor and stays open until dismissed, rather than following hover and focus. With anchor or externalAnchor, open and close it with show() and hide(). Use it when the tooltip holds actions or text a reader needs time with. See Persistent. |
position | TooltipPositionTypeTooltipPosition.StartStart, .StartCenter, .StartEnd, .CenterStart, .CenterEnd, .EndStart, .EndCenter, .EndEnddefault TooltipPosition.EndCenter, from the style configuration | Where the tooltip sits relative to its anchor, named as the block position then the inline position: end-center is below the anchor and centered. The inline position mirrors in right-to-left text. See Position. |
Setting persistentshow() and hide() toggle a persistent tooltip.
Children
| Child | Description |
|---|---|
children | The anchor element. Not used, and not rendered, when anchor or externalAnchor supplies the anchor. |
a child with slot="sub-heading" | A small heading above the content. |
a child with slot="content" | The tooltip's main content, as text or elements. |
a child with slot="action" | A button or other action the reader can take from the tooltip. |
Methods
Call these on the element the ref holds.
| Method | Returns | Description |
|---|---|---|
hide() | void | Closes the tooltip. A pending hover or focus delay is canceled, and focus inside the tooltip returns to the anchor. |
show() | void | Opens the tooltip at the current anchor. A pending hover or focus delay is canceled, so this call decides. |
Parameters
| Parameter | Type | Description |
|---|---|---|
Anchor | string? | The id of the element the tooltip attaches to. The element is found in the same page or component as the tooltip, and the tooltip does not wrap it.Takes precedence over the AnchorElement parameter.Note: an id cannot name an element inside another component. Use ExternalAnchor with the AnchorElement parameter for that case. See Anchors and methods. |
AnchorElement | ElementReference? | The element the tooltip attaches to and positions against.Resolves in precedence order: the Anchor idref, then an element assigned to this property, then the content the tooltip wraps.Assign an element, with ExternalAnchor, to anchor to one an id cannot find, such as an element inside another component. |
ExternalAnchor | bool?default false | Set this when the anchor is not slotted into the tooltip: the tooltip attaches to the element AnchorElement resolves to, and the default slot is ignored. See Anchors and methods. |
Persistent | bool?default false | Opens on a click or tap on a slotted anchor and stays open until dismissed, rather than following hover and focus. With Anchor or ExternalAnchor, open and close it with show() and hide(). Use it when the tooltip holds actions or text a reader needs time with. See Persistent. |
Position | TooltipPosition?TooltipPosition.StartStart, .StartCenter, .StartEnd, .CenterStart, .CenterEnd, .EndStart, .EndCenter, .EndEnddefault TooltipPosition.EndCenter, from the style configuration | Where the tooltip sits relative to its anchor, named as the block position then the inline position: end-center is below the anchor and centered. The inline position mirrors in right-to-left text. See Position. |
Setting persistentshow() and hide() toggle a persistent tooltip.
Render fragments
Once you write Action or any other fragment as a child element, the main content must go in an explicit <ChildContent> too; markup beside <Action> is a compile error. Here ChildContent is: The anchor element.
<CbRichTooltip>
<Action>Content</Action>
<ChildContent>Main content</ChildContent>
</CbRichTooltip>
| Parameter | Type | Description |
|---|---|---|
Action | RenderFragment? | A button or other action the reader can take from the tooltip. |
ChildContent | RenderFragment? | The anchor element. Not used, and not rendered, when Anchor or ExternalAnchor supplies the anchor. |
Content | RenderFragment? | The tooltip's main content, as text or elements. |
SubHeading | RenderFragment? | A small heading above the content. |
Inputs
| Input | Type | Description |
|---|---|---|
anchor | string | The id of the element the tooltip attaches to. The element is found in the same page or component as the tooltip, and the tooltip does not wrap it.Takes precedence over the anchorElement input.Note: an id cannot name an element inside another component. Use externalAnchor with the anchorElement input for that case. See Anchors and methods. |
anchorElement | HTMLElement | The element the tooltip attaches to and positions against.Resolves in precedence order: the anchor idref, then an element assigned to this property, then the content the tooltip wraps.Assign an element, with externalAnchor, to anchor to one an id cannot find, such as an element inside another component. |
externalAnchor | booleandefault false | Set this when the anchor is not slotted into the tooltip: the tooltip attaches to the element anchorElement resolves to, and the default slot is ignored. See Anchors and methods. |
persistent | booleandefault false | Opens on a click or tap on a slotted anchor and stays open until dismissed, rather than following hover and focus. With anchor or externalAnchor, open and close it with show() and hide(). Use it when the tooltip holds actions or text a reader needs time with. See Persistent. |
position | TooltipPositionTypeTooltipPosition.StartStart, .StartCenter, .StartEnd, .CenterStart, .CenterEnd, .EndStart, .EndCenter, .EndEnddefault TooltipPosition.EndCenter, from the style configuration | Where the tooltip sits relative to its anchor, named as the block position then the inline position: end-center is below the anchor and centered. The inline position mirrors in right-to-left text. See Position. |
Setting persistentshow() and hide() toggle a persistent tooltip.
Content projection
| Content | Description |
|---|---|
content with no slot | The anchor element. Not used, and not rendered, when anchor or externalAnchor supplies the anchor. |
an element with slot="sub-heading" | A small heading above the content. |
an element with slot="content" | The tooltip's main content, as text or elements. |
an element with slot="action" | A button or other action the reader can take from the tooltip. |
Methods
Call these on the element the ref holds.
| Method | Returns | Description |
|---|---|---|
hide() | void | Closes the tooltip. A pending hover or focus delay is canceled, and focus inside the tooltip returns to the anchor. |
show() | void | Opens the tooltip at the current anchor. A pending hover or focus delay is canceled, so this call decides. |
Props
| Prop | Type | Description |
|---|---|---|
anchor | string | The id of the element the tooltip attaches to. The element is found in the same page or component as the tooltip, and the tooltip does not wrap it.Takes precedence over the anchorElement prop.Note: an id cannot name an element inside another component. Use externalAnchor with the anchorElement prop for that case. See Anchors and methods. |
anchorElement | HTMLElement | The element the tooltip attaches to and positions against.Resolves in precedence order: the anchor idref, then an element assigned to this property, then the content the tooltip wraps.Assign an element, with externalAnchor, to anchor to one an id cannot find, such as an element inside another component. |
externalAnchor | booleandefault false | Set this when the anchor is not slotted into the tooltip: the tooltip attaches to the element anchorElement resolves to, and the default slot is ignored. See Anchors and methods. |
persistent | booleandefault false | Opens on a click or tap on a slotted anchor and stays open until dismissed, rather than following hover and focus. With anchor or externalAnchor, open and close it with show() and hide(). Use it when the tooltip holds actions or text a reader needs time with. See Persistent. |
position | TooltipPositionTypeTooltipPosition.StartStart, .StartCenter, .StartEnd, .CenterStart, .CenterEnd, .EndStart, .EndCenter, .EndEnddefault TooltipPosition.EndCenter, from the style configuration | Where the tooltip sits relative to its anchor, named as the block position then the inline position: end-center is below the anchor and centered. The inline position mirrors in right-to-left text. See Position. |
Setting persistentshow() and hide() toggle a persistent tooltip.
Slots
| Slot | Description |
|---|---|
default | The anchor element. Not used, and not rendered, when anchor or externalAnchor supplies the anchor. |
action | A button or other action the reader can take from the tooltip. |
content | The tooltip's main content, as text or elements. |
sub-heading | A small heading above the content. |
Methods
Call these on the element the ref holds.
| Method | Returns | Description |
|---|---|---|
hide() | void | Closes the tooltip. A pending hover or focus delay is canceled, and focus inside the tooltip returns to the anchor. |
show() | void | Opens the tooltip at the current anchor. A pending hover or focus delay is canceled, so this call decides. |
Props
| Prop | Type | Description |
|---|---|---|
anchor | string | The id of the element the tooltip attaches to. The element is found in the same page or component as the tooltip, and the tooltip does not wrap it.Takes precedence over the anchorElement prop.Note: an id cannot name an element inside another component. Use externalAnchor with the anchorElement prop for that case. See Anchors and methods. |
anchorElement | HTMLElement | The element the tooltip attaches to and positions against.Resolves in precedence order: the anchor idref, then an element assigned to this property, then the content the tooltip wraps.Assign an element, with externalAnchor, to anchor to one an id cannot find, such as an element inside another component. |
externalAnchor | booleandefault false | Set this when the anchor is not slotted into the tooltip: the tooltip attaches to the element anchorElement resolves to, and the default slot is ignored. See Anchors and methods. |
persistent | booleandefault false | Opens on a click or tap on a slotted anchor and stays open until dismissed, rather than following hover and focus. With anchor or externalAnchor, open and close it with show() and hide(). Use it when the tooltip holds actions or text a reader needs time with. See Persistent. |
position | TooltipPositionTypeTooltipPosition.StartStart, .StartCenter, .StartEnd, .CenterStart, .CenterEnd, .EndStart, .EndCenter, .EndEnddefault TooltipPosition.EndCenter, from the style configuration | Where the tooltip sits relative to its anchor, named as the block position then the inline position: end-center is below the anchor and centered. The inline position mirrors in right-to-left text. See Position. |
Setting persistentshow() and hide() toggle a persistent tooltip.
Snippets
| Snippet | Description |
|---|---|
children | The anchor element. Not used, and not rendered, when anchor or externalAnchor supplies the anchor. |
subHeadingSnippet | A small heading above the content. |
contentSnippet | The tooltip's main content, as text or elements. |
actionSnippet | A button or other action the reader can take from the tooltip. |
Methods
Call these on the element the ref holds.
| Method | Returns | Description |
|---|---|---|
hide() | void | Closes the tooltip. A pending hover or focus delay is canceled, and focus inside the tooltip returns to the anchor. |
show() | void | Opens the tooltip at the current anchor. A pending hover or focus delay is canceled, so this call decides. |
A value is what the token defaults to; selecting it copies the token's name.
Tokens
| Token | Value |
|---|---|
--ct-rich-tooltip-action-label-text-color | --ct-sys-color-primary --ct-rich-tooltip-action-label-text-color |
--ct-rich-tooltip-action-label-text-font | --ct-sys-typescale-label-large-font --ct-rich-tooltip-action-label-text-font |
--ct-rich-tooltip-action-label-text-line-height | --ct-sys-typescale-label-large-line-height --ct-rich-tooltip-action-label-text-line-height |
--ct-rich-tooltip-action-label-text-size | --ct-sys-typescale-label-large-size --ct-rich-tooltip-action-label-text-size |
--ct-rich-tooltip-action-label-text-tracking | --ct-sys-typescale-label-large-tracking --ct-rich-tooltip-action-label-text-tracking |
--ct-rich-tooltip-action-label-text-weight | --ct-sys-typescale-label-large-weight --ct-rich-tooltip-action-label-text-weight |
--ct-rich-tooltip-container-color | --ct-sys-color-surface-container --ct-rich-tooltip-container-color |
--ct-rich-tooltip-container-elevation | 2 --ct-rich-tooltip-container-elevation |
--ct-rich-tooltip-container-max-width | 280px --ct-rich-tooltip-container-max-width |
--ct-rich-tooltip-subhead-color | --ct-sys-color-on-surface-variant --ct-rich-tooltip-subhead-color |
--ct-rich-tooltip-subhead-font | --ct-sys-typescale-title-small-font --ct-rich-tooltip-subhead-font |
--ct-rich-tooltip-subhead-line-height | --ct-sys-typescale-title-small-line-height --ct-rich-tooltip-subhead-line-height |
--ct-rich-tooltip-subhead-size | --ct-sys-typescale-title-small-size --ct-rich-tooltip-subhead-size |
--ct-rich-tooltip-subhead-tracking | --ct-sys-typescale-title-small-tracking --ct-rich-tooltip-subhead-tracking |
--ct-rich-tooltip-subhead-weight | --ct-sys-typescale-title-small-weight --ct-rich-tooltip-subhead-weight |
--ct-rich-tooltip-supporting-text-color | --ct-sys-color-on-surface-variant --ct-rich-tooltip-supporting-text-color |
--ct-rich-tooltip-supporting-text-font | --ct-sys-typescale-body-medium-font --ct-rich-tooltip-supporting-text-font |
--ct-rich-tooltip-supporting-text-line-height | --ct-sys-typescale-body-medium-line-height --ct-rich-tooltip-supporting-text-line-height |
--ct-rich-tooltip-supporting-text-size | --ct-sys-typescale-body-medium-size --ct-rich-tooltip-supporting-text-size |
--ct-rich-tooltip-supporting-text-tracking | --ct-sys-typescale-body-medium-tracking --ct-rich-tooltip-supporting-text-tracking |
--ct-rich-tooltip-supporting-text-weight | --ct-sys-typescale-body-medium-weight --ct-rich-tooltip-supporting-text-weight |
Names and states
A screen reader announces a rich tooltip as a tooltip, or as a dialog while persistent
- The tooltip is named by its own content.
- A screen reader reads the
sub-headingandcontenttext after the anchor's name, as a description. Text that only repeats the name is skipped, and theactionslot is never part of the description. - A persistent tooltip describes nothing. It is a disclosure the anchor controls, so a screen reader announces a button, link, or other button-like anchor as expanded while the tooltip is open.
- The tooltip never names its anchor. Give the anchor its own accessible name, and anchor on a control that takes keyboard focus, such as a button.
- A persistent tooltip on an anchor that is not button-like logs a warning. Enter or Space on a slotted anchor opens it, as a click does.
Keyboard and focus
| Key | Action |
|---|---|
| Tab | Moves focus onto the anchor, which opens a standard tooltip, and then onto the action, which keeps the tooltip open. |
| Enter, Space | Open or close a persistent tooltip from a slotted anchor that is not a button. |
| Escape | Closes a visible tooltip. |
On a button anchor, Enter and Space are the button's own behavior, and its click toggles a persistent tooltip.
- When the tooltip closes with focus inside it, focus returns to the anchor.
- A standard tooltip also opens on a click, and a press outside closes it.
- The tooltip draws no focus ring of its own; the anchor and the action are controls you supply.
Pointer and touch
- A click or tap on the anchor opens a standard tooltip and toggles a persistent one.
- The tooltip stays up for a grace period after the pointer leaves the anchor, so the pointer can reach the action.
- The tooltip sets no touch target size. The anchor and the action are your controls, so give each a target of at least 24 by 24 pixels, as WCAG 2.5.8 asks.
Display settings
- Reduced motion: the fade is skipped, and the tooltip appears and disappears at once.
- Right-to-left: the tooltip's position flips with the reading direction, and its content keeps the direction of the surrounding text.
Standards
With its defaults, the rich tooltip meets one WCAG 2.2 success criterion:
- 1.4.13 Content on Hover or Focus (AA)
Two more depend on how you use it: