Skip to content

Tooltips are small text-based components that when triggered by a reference element provide context to the user.

Overview

Tooltips float over other elements in the z-axis and provide text to quickly assist the user to understand context, actions, and other elements. A Tooltip can be a helpful UX device to give the user clarity before committing to an action. Avoid relying heavily on Tooltips, as you should prefer headers and labels that accurately describe a workflow. Tooltip positioning can be automatic or manually set to avoid clipping in the interface.

Tooltip should not be placed within its reference element, and it is recommended to place the component shallowly in the DOM.

To support interactive content, consider Popover.

For more advanced floating workflows, refer to Dialog.

Usage

  • General helper text
  • Succinct action hints

Sample

Best practices

Below are important guidelines on using the Tooltip component.

Correct Tooltip directional
Do use directional props based on the placement of the item generating the Tooltip.
Avoid Tooltip directional
Avoid using directional props that could make the Tooltip fall off of the interface.
Correct Tooltip on interactive elements
Do use Tooltips on interactive, focusable elements to ensure content is accessible to keyboard and assistive technology users.
Avoid Tooltip disabled elements
Avoid using Tooltips on disabled or non-focusable elements. Disabled elements and their associated Tooltip content are not accessible to keyboard users.

Accessibility

It is strongly recommended to house the component's content in an element, such as a span or p, providing context to assistive technologies when accessed.

Tooltips should not be placed on disabled components, as keyboard users will not be able to access the component's contents. Instead, it is recommended to change the component's appearance using the kind and/or appearance attributes and prevent its default JavaScript behavior with the preventDefault() method:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
<!-- Non-disabled button with tooltip-->
<calcite-button id="non-disabled-btn" kind="neutral" label="Add new folder not available" icon-start="folder-plus"></calcite-button>
<calcite-tooltip reference-element="non-disabled-btn">
  <span>Context on prevented interaction provided to assistive technologies</span>
</calcite-tooltip>

<script>
  document.getElementById("non-disabled-btn").addEventListener("click", (evt) => evt.preventDefault());
</script>

Keyboard navigation

KeyFunction
TabMoves focus to access the component's contents from its reference element. If the current focus is the reference element, focus will leave the element.
Tab and ShiftMoves focus to access the component's contents from its reference element. If the current focus is the reference element, focus will leave the element.

Writing and copy

Correct Tooltip content length
Do use Tooltips as brief text helpers. Prefer brevity.
Avoid Tooltip content length
Avoid using Tooltips with more than one sentence or 75 characters. Prefer Popover or Dialog for more content.
Correct Tooltip helpful
Do use actionable verbiage when applicable.
Avoid Tooltip not helpful
Avoid being vague or baiting with Tooltips.
Correct Tooltip punctuation
Do put helpful statements in Tooltips.
Avoid Tooltip punctuation
Avoid having questions in Tooltips.
  • Tooltip text should be succinct and straight to the point
  • Periods are not necessary for ending Tooltip text
  • Avoid contractions such as "you're", "aren't", "don't", and "can't" to avoid confusion and to assist with internationalization
  • For longer content, please consider Popover
  • Recommended character maximum: 75

API reference

Properties

PropertyAttributeDescriptionTypeDefault
closeOnClickclose-on-clickCloses the component when the referenceElement is clicked.booleanfalse
labellabel
deprecatedin v1.5.0, removal target v6.0.0 - No longer necessary. Overrides the context of the component's text description, which could confuse assistive technology users.
Specifies an accessible label for the component.
string
offsetDistanceoffset-distanceSpecifies the distance to position the component away from the referenceElement.number
offsetSkiddingoffset-skiddingSpecifies the distance to position the component along the referenceElement.number0
openopenWhen true, the component is open.booleanfalse
overlayPositioningoverlay-positioningSpecifies the type of positioning to use for overlaid content, where: "absolute" works for most cases - positioning the component inside of overflowing parent containers, which affects the container's layout, and "fixed" is used to escape an overflowing parent container, or when the reference element's position CSS property is "fixed".OverlayPositioning"absolute"
placementplacementDetermines where the component will be positioned relative to the referenceElement.LogicalPlacement"auto"
referenceElementreference-elementThe referenceElement is used to position the component according to its placement value. Setting the value to an HTMLElement is preferred so the component does not need to query the DOM. However, a string id of the reference element can also be used. The component should not be placed within its own referenceElement to avoid unintended behavior.ReferenceElement | string
topLayerDisabledtop-layer-disabledWhen true and the component is open, disables top layer placement. Only set this if you need complex z-index control or if top layer placement causes conflicts with third-party components.booleanfalse

Slots

NameDescription
default (unnamed)A slot for adding text.

Styles

NameDescription
--calcite-tooltip-background-colorSpecifies the component's background color.
--calcite-tooltip-border-colorSpecifies the component's border color.
--calcite-tooltip-corner-radiusSpecifies the component's corner radius.
--calcite-tooltip-max-size-xSpecifies the component's maximum width.
--calcite-tooltip-text-colorSpecifies the component's text color.

Events

NameDescriptionBehavior
calciteTooltipBeforeCloseFires when the component is requested to be closed and before the closing transition begins.bubblescomposed
calciteTooltipBeforeOpenFires when the component is added to the DOM but not rendered, and before the opening transition begins.bubblescomposed
calciteTooltipCloseFires when the component is closed and animation is complete.bubblescomposed
calciteTooltipOpenFires when the component is open and animation is complete.bubblescomposed

Methods

NameDescriptionSignature
componentOnReadyCreate a promise that resolves once component is fully loaded.componentOnReady(): Promise<this>
repositionUpdates the position of the component.reposition(delayed?: boolean): Promise<void>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.