Angular Tooltip - Getting Started

NOTE
Before you start the tutorial, ensure DevExtreme is installed in your application.

Tooltip is a UI component that allows you to display information over a specific element in your application.

This tutorial guides you through the following steps:

  • Add a Tooltip to a page and configure core component settings.
  • Customize Tooltip appearance.

The following live example demonstrates the result:

Each section in this tutorial describes a single configuration step. You can find the complete source code in the following GitHub repository:

View on GitHub

Create and Configure Tooltip

Add DevExtreme to your Angular application and use the code below to create a Tooltip. To display the component, specify a target and define the showEvent or visible property.

app.component.html
app.module.ts
  • <dx-tooltip
  • target="#target"
  • showEvent="mouseenter"
  • ></dx-tooltip>
  • import { NgModule } from '@angular/core';
  • import { BrowserModule } from '@angular/platform-browser';
  • import { DxTooltipModule } from 'devextreme-angular/ui/tooltip';
  • import { AppRoutingModule } from './app-routing.module';
  • import { AppComponent } from './app.component';
  •  
  • @NgModule({
  • declarations: [
  • AppComponent
  • ],
  • imports: [
  • BrowserModule,
  • AppRoutingModule,
  • DxTooltipModule,
  • ],
  • providers: [],
  • bootstrap: [AppComponent]
  • })
  • export class AppModule { }

This example creates three Button components and assigns Tooltips to them. Button ID attributes are specified as Tooltip targets. Additionally, this example configures the hideEvent property for all Tooltips:

app.component.html
app.module.ts
  • <div class="dx-viewport">
  • <div class="buttons">
  • <dx-button id="like" icon="like"></dx-button>
  • <dx-button id="trash" icon="trash"></dx-button>
  • <dx-button id="info" icon="info"></dx-button>
  • </div>
  • <div class="tooltips">
  • <dx-tooltip
  • target="#like"
  • showEvent="mouseenter"
  • hideEvent="mouseleave"
  • ></dx-tooltip>
  • <dx-tooltip
  • target="#trash"
  • showEvent="mouseenter"
  • hideEvent="mouseleave"
  • ></dx-tooltip>
  • <dx-tooltip
  • target="#info"
  • showEvent="mouseenter"
  • hideEvent="mouseleave"
  • ></dx-tooltip>
  • </div>
  • </div>
  • import { NgModule } from '@angular/core';
  • import { BrowserModule } from '@angular/platform-browser';
  • import { DxButtonModule } from 'devextreme-angular/ui/button';
  • import { DxTooltipModule } from 'devextreme-angular/ui/tooltip';
  • import { AppRoutingModule } from './app-routing.module';
  • import { AppComponent } from './app.component';
  •  
  • @NgModule({
  • declarations: [
  • AppComponent
  • ],
  • imports: [
  • BrowserModule,
  • AppRoutingModule,
  • DxButtonModule,
  • DxTooltipModule,
  • ],
  • providers: [],
  • bootstrap: [AppComponent]
  • })
  • export class AppModule { }

Customize Tooltip

To customize Tooltip content, specify contentTemplate. If you assign a string to this property, Tooltip displays plain text in its container:

app.component.html
  • <div class="tooltips">
  • <dx-tooltip
  • contentTemplate="Like"
  • ></dx-tooltip>
  • <dx-tooltip
  • contentTemplate="trashTooltip"
  • >
  • <div *dxTemplate="let model of 'trashTooltip'">
  • <div class="red-tooltip">Delete</div>
  • </div>
  • </dx-tooltip>
  • <dx-tooltip
  • contentTemplate="infoTooltip"
  • >
  • <div *dxTemplate="let model of 'infoTooltip'">
  • <div class="blue-tooltip">Info</div>
  • </div>
  • </dx-tooltip>
  • </div>

You can use CSS to customize the Tooltip's appearance. The code snippets above assigned CSS classes to all tooltips. This example defines those styles (.red-tooltip and .blue-tooltip):

app.component.scss
  • ::ng-deep .dx-overlay-content:has(.blue-tooltip),
  • ::ng-deep .dx-overlay-content:has(.blue-tooltip) .dx-popover-arrow::after {
  • background-color: #0f6cbd;
  • color: white;
  • }
  •  
  • ::ng-deep .dx-overlay-content:has(.red-tooltip),
  • ::ng-deep .dx-overlay-content:has(.red-tooltip) .dx-popover-arrow::after {
  • background-color: #d13438;
  • color: white;
  • }
See Also