Angular Material mat-tab-group - GeeksforGeeks

16 Feb, 2021

Angular Material is a UI component library that is developed by the Angular team to build design components for desktop and mobile web applications. In order to install it, we need to have angular installed in our project, once you have it you can enter the below command and can download it. mat-tab-group is used mainly for navbar requirements when we have multiple tabs to display.
Installation:
ng add @angular/material
Approach:
First, install the angular material using the above-mentioned command.
After completing the installation, Import ‘MatTabsModule’ from ‘@angular/material/tabs’ in the app.module.ts file.
Then use the <mat-tab-group> tag to group all the items inside this group tag.
Inside the <mat-tab-group> tag we need to use <mat-tab> tag for every item.
We can also style the tabs basing upon the position like start, center, and end. For this, we need to use a property called mat-align-tabs.
If we want to change the theme then we can change it by using the color property. In angular we have 3 themes, they are primary, accent, and warn.
Once done with the above steps then serve or start the project.
Example:
app.module.ts
 

 
 










import { NgModule } from '@angular/core';  
import { BrowserModule } from '@angular/platform-browser';  
import { FormsModule } from '@angular/forms';  
import { MatTabsModule } from '@angular/material/tabs';  
      
import { AppComponent } from './app.component';  
import { BrowserAnimationsModule } from  
'@angular/platform-browser/animations'; 
  
  
@NgModule({  
  imports:  
  [ BrowserModule,  
    FormsModule,  
    MatTabsModule, 
    BrowserAnimationsModule],  
  declarations: [ AppComponent ],  
  bootstrap: [ AppComponent ]  
})  
  
export class AppModule { }






app.component.html
 

 
 










<p> 
   Implementation of mat-tab-group for  
   center style and for default theme 
</p> 
  
<mat-tab-group mat-align-tabs="center"> 
  <mat-tab label="Home">Home Content</mat-tab> 
  <mat-tab label="Overview">Overview Content</mat-tab> 
</mat-tab-group> 
<br> 
  
  
<p> 
  Implementation of mat-tab-group for center  
  style and for primary theme 
</p> 
  
<mat-tab-group mat-align-tabs="center" backgroundColor="primary"> 
  <mat-tab label="Home">Home Content</mat-tab> 
  <mat-tab label="Overview">Overview Content</mat-tab> 
</mat-tab-group> 
<br> 
  
  
<p> 
  Implementation of mat-tab-group for center  
  style and for accent theme 
</p> 
  
<mat-tab-group mat-align-tabs="center" backgroundColor="accent"> 
  <mat-tab label="Home">Home Content</mat-tab> 
  <mat-tab label="Overview">Overview Content</mat-tab> 
</mat-tab-group>






Output:

Angular-material


Picked


AngularJS


Web Technologies

Writing code in comment? 
                                    Please use ide.geeksforgeeks.org, 
                                    generate link and share the link here.
                                
Top 10 Angular Libraries For Web Developers
How to use <mat-chip-list> and <mat-chip> in Angular Material ?
Angular PrimeNG Dropdown Component
Angular 10 (blur) Event
Angular 10 (focus) Event
Express.js express.Router() Function
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript