# Tooltip

**Tooltips** provide concise supplementary information when users hover over or focus on a UI element, typically buttons or icons.

## Usage

Tooltips briefly appear over other content to provide additional context. They are triggered by **hover or focus**, making them particularly useful for desktop interactions.

Since tooltips are temporary and generally not accessible on touch devices, **they should not contain critical or primary information.**

![Tooltip](<../images/tooltip.png>)

Tooltips are applied to controls that rely solely on an icon, such as [icon buttons](<https://element.siemens.io/components/buttons-menus/buttons/>), [icon-only tabs](<https://element.siemens.io/components/layout-navigation/tabs/>), [application header](<https://element.siemens.io/components/layout-navigation/application-header/>) and collapsed versions of [vertical navigation](<https://element.siemens.io/components/layout-navigation/vertical-navigation/>) and the [side panel](<https://element.siemens.io/components/layout-navigation/side-panel/>).

They may also reveal truncated text **only when the element is focusable**, for example a [tree node](<https://element.siemens.io/components/lists-tables-trees/tree-view/>).

![Tooltip](<../images/tooltip-examples.png>)

### When to use

- To clarify an element’s function or provide extra context for icons or buttons.
- For supplementary, non-essential information only.

### Best practices

- Keep text brief.
- Do not include interactive elements.
- Use sparingly to reduce visual noise.
- Apply tooltips only to interactive, keyboard-focusable elements.
- Never add tooltips on disabled elements.
- When implementing tooltips on touch devices, ensure they appear on tap and that this interaction does not conflict with other functionalities.
- Always use the tooltip component, not the browser’s native tooltip.
- Use a 500ms show delay and allow dismissal on pointer leave, focus loss or pressing **Escape**.

## Design

### Elements

![Tooltip elements](<../images/tooltip-elements.png>)

> 1. Container, 2. Text content, 3. Tip

### Placement

Four position options are available: **top**, **end**, **bottom** and **start**. Besides that, **auto** option may be used to detect a position that fits the component on the screen.

![Tooltip placement](<../images/tooltip-placement.png>)

### Alternatives to tooltips

Tooltips are temporary, implicit interactions that can interrupt the user’s flow. Because of these limitations, **tooltips should be considered a last resort.** Consider these strategies instead:

#### Reevaluate the need for tooltips

Consider whether the tooltip is actually needed. Avoid using them to repeat information that users can easily access.

![Tooltip alternative - revaluate](<../images/tooltip-revaluate.png>)

#### The right time and place

Think about where and when information will be most useful to users. Place key details directly on the interface in a clear, accessible spot, ensuring information is available at the right moment.

![Tooltip alternative - information location](<../images/tooltip-information-location.png>)

#### Use disclosures

Leverage expandable elements like dropdowns, [accordions](<https://element.siemens.io/components/layout-navigation/accordion/>), or show/hide buttons to reveal additional information as needed, providing deeper context only when required.

![Tooltip alternative - disclosure](<../images/tooltip-disclosure.png>)

#### Use intuitive icons and labels

Tooltips should only replace labels for universally understood icons (e.g., edit, share). For complex or less intuitive icons, always display labels. If space is limited, ensure the legend is accessible elsewhere for users to understand the meaning.

#### Use popovers

For information that needs detailed explanation, use [popovers](<https://element.siemens.io/components/status-notifications/popover/>), which are triggered explicitly and can hold more content.

| Component | Tooltip | Popover |
| --- | --- | --- |
| **Purpose** | Provides supplementary, non-essential information. | Displays contextual information or interactive elements. |
| **Interaction** | Appears on **hover or keyboard focus**. | Opens on **selection**. |
| **Dismissal** | Dismisses on pointer leave, focus loss or pressing **Escape**. | Requires user interaction to close. |
| **Interactivity** | Non-interactive, only displays text. | Can contain buttons, links, and inputs. |

## Code

Element supports several ways to show tooltips depending on the use case, but all share the following constraints:

- **Display Triggers:** Tooltips appear on element hover or keyboard focus.
- **Dismissal:** Press **Escape** to dismiss a visible tooltip, even while its trigger remains hovered or focused.
- **No Interactive Content:** Interactive elements (links, buttons, inputs) are not permitted inside a tooltip.
- **Need Interactivity?** Use a [popover](<https://element.siemens.io/components/status-notifications/popover/>) component instead of a tooltip.

## Standard tooltip

Use the `siTooltip` directive when you need to show supplementary information. It must be on an interactive element like a button or link. Otherwise, it cannot be reached by keyboard user. It is using `aria-describe` to expose its content to screen reader.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { afterNextRender, Component, ElementRef, viewChild } from '@angular/core';
import { SiIconComponent } from '@siemens/element-ng/icon';
import { SiTabComponent, SiTabsetComponent } from '@siemens/element-ng/tabs';
import { SiTooltipDirective } from '@siemens/element-ng/tooltip';

@Component({
  selector: 'app-sample',
  imports: [SiIconComponent, SiTooltipDirective, SiTabsetComponent, SiTabComponent],
  templateUrl: './si-tooltip.html'
})
export class SampleComponent {
  readonly focusButton = viewChild.required<ElementRef<HTMLButtonElement>>('focusButton');

  html = `<strong>I'm a microwave</strong>`;

  constructor() {
    afterNextRender(() => {
      const button = this.focusButton();
      button.nativeElement.focus();
    });
  }
}
```

Template:

```html
<div class="p-5">
  <section class="d-flex align-items-center gap-4 mb-5">
    <div class="btn-group" role="group" aria-label="File operations">
      <button
        type="button"
        class="btn btn-icon btn-primary"
        siTooltip="Open file"
        aria-label="Open file"
      >
        <si-icon icon="element-folder-open" />
      </button>
      <button type="button" class="btn btn-icon btn-primary" siTooltip="Save" aria-label="Save">
        <si-icon icon="element-save" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-primary"
        siTooltip="Download"
        aria-label="Download"
      >
        <si-icon icon="element-download" />
      </button>
      <button type="button" class="btn btn-icon btn-primary" siTooltip="Share" aria-label="Share">
        <si-icon icon="element-share" />
      </button>
    </div>
    <div class="btn-group" role="group" aria-label="Basic actions">
      <button type="button" class="btn btn-icon btn-secondary" siTooltip="Edit" aria-label="Edit">
        <si-icon icon="element-edit" />
      </button>
      <button type="button" class="btn btn-icon btn-secondary" siTooltip="Copy" aria-label="Copy">
        <si-icon icon="element-copy" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-secondary"
        siTooltip="Delete"
        aria-label="Delete"
      >
        <si-icon icon="element-delete" />
      </button>
    </div>
    <div class="btn-group" role="group" aria-label="Template examples">
      <button
        #focusButton
        type="button"
        class="btn btn-icon btn-tertiary"
        aria-label="Template HTML example"
        [siTooltip]="tooltipTemplateHtml"
      >
        <si-icon icon="element-microwave-on" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-tertiary"
        aria-label="Template example"
        [siTooltip]="tooltipTemplate"
      >
        <si-icon icon="element-light-desk" />
      </button>
    </div>
  </section>

  <section class="mb-5">
    <h4>Tooltip placement</h4>
    <div class="btn-group" role="group" aria-label="Tooltip placement">
      <button
        type="button"
        class="btn btn-icon btn-secondary"
        siTooltip="Auto placement"
        placement="auto"
        aria-label="Auto placement"
      >
        <si-icon icon="element-language" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-secondary"
        siTooltip="Top"
        placement="top"
        aria-label="Top"
      >
        <si-icon icon="element-up-2" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-secondary"
        siTooltip="Bottom"
        placement="bottom"
        aria-label="Bottom"
      >
        <si-icon icon="element-down-2" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-secondary"
        siTooltip="Start"
        placement="start"
        aria-label="Start"
      >
        <si-icon icon="element-left-2" />
      </button>
      <button
        type="button"
        class="btn btn-icon btn-secondary"
        siTooltip="End"
        placement="end"
        aria-label="End"
      >
        <si-icon icon="element-right-2" />
      </button>
    </div>
  </section>

  <section class="mb-5">
    <h4>Other examples</h4>
    <div class="d-flex align-items-start gap-4" style="max-width: 300px">
      <si-tabset class="w-50">
        <si-tab heading="Favorites" icon="element-favorites" siTooltip="Your favorites">
          <p class="mt-4">Favorites content</p>
        </si-tab>
        <si-tab heading="Notifications" icon="element-alarm" siTooltip="View notifications">
          <p class="mt-4">Notifications content</p>
        </si-tab>
        <si-tab heading="Settings" icon="element-edit" siTooltip="Adjust settings">
          <p class="mt-4">Settings content</p>
        </si-tab>
      </si-tabset>
    </div>
  </section>
</div>

<ng-template #tooltipTemplateHtml> Hello, <span [innerHtml]="html"></span> </ng-template>
<ng-template #tooltipTemplate>
  <div>
    <si-icon class="si-display" icon="element-light-desk-filled" />
  </div>
  <div>I'm the tooltip template</div>
</ng-template>
```

## Tooltip for text overflow

Use the `siTooltipOverflow` directive to display an element's full text content in a tooltip only when the text is visually truncated. The directive uses the host element’s text as the tooltip content, so no separate tooltip text is needed.

> [!NOTE]
>
> **Automatic text truncation**
>
> The directive automatically applies the `text-truncate` class to the host element. You do not need to add this class manually.

Apply the directive to an interactive, keyboard-focusable element with a constrained width so its text can overflow.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { SiTooltipOverflowDirective } from '@siemens/element-ng/tooltip';

@Component({
  selector: 'app-sample',
  imports: [SiTooltipOverflowDirective],
  templateUrl: './si-tooltip-overflow.html'
})
export class SampleComponent {}
```

Template:

```html
<div class="p-5 d-flex flex-column align-items-start gap-5">
  <button
    type="button"
    class="btn btn-secondary d-inline"
    style="max-width: 200px"
    siTooltipOverflow
  >
    A long time ago in a galaxy far, far away...
  </button>
  <a href="https://siemens.github.io/element/" style="max-width: 200px" siTooltipOverflow>
    Explore the Siemens Element design system
  </a>
</div>
```

### [SiTooltipDirective](<https://github.com/siemens/element/blob/main/projects/element-ng/tooltip/si-tooltip.directive.ts#L26-L79>)

**Kind:** directive

**Selector:** `[siTooltip]`

```
import { SiTooltipDirective } from '@siemens/element-ng/tooltip';
```

```
directive SiTooltipDirective
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [isDisabled](<https://github.com/siemens/element/blob/main/projects/element-ng/tooltip/si-tooltip.directive.ts#L48-L48>) | `boolean` | `false` | Allows the tooltip to be disabled |
| [placement](<https://github.com/siemens/element/blob/main/projects/element-ng/tooltip/si-tooltip.directive.ts#L41-L41>) | `"start" \| "end" \| "bottom" \| "auto" \| "top"` | `'auto'` | The placement of the tooltip. One of 'top', 'start', end', 'bottom' |
| [siTooltip](<https://github.com/siemens/element/blob/main/projects/element-ng/tooltip/si-tooltip.directive.ts#L34-L34>) | `TranslatableString \| TemplateRef<any>` | `''` | The tooltip text to be displayed |
| [tooltipContext](<https://github.com/siemens/element/blob/main/projects/element-ng/tooltip/si-tooltip.directive.ts#L60-L60>) | `unknown` |  | The context for the attached template |
| [tooltipScrollStrategy](<https://github.com/siemens/element/blob/main/projects/element-ng/tooltip/si-tooltip.directive.ts#L55-L55>) | `ScrollStrategy` | `defaultConnectedOverlayScrollStrategy()` | CDK scroll strategy used for the tooltip overlay. |

### Types Documentation

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```
