Skip to content
Related Articles

Related Articles

Improve Article

How to use <mat-divider> in Angular Material ?

  • Last Updated : 05 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-divider> tag is used to separate two sections or content with a horizontal line.

Installation syntax:

ng add @angular/material

Approach:

  • First, install the angular material using the above-mentioned command.
  • After completing the installation, Import ‘MatDividerModule’ from ‘@angular/material/divider’ in the app.module.ts file.
  • After importing the ‘MatDividerModule’ we need to use <mat-divider> tag.
  • When we use <mat-divider>, a horizontal grey line is rendered on the screen.
  • The main purpose of this tag is to separate any two-block, div, or any sections.
  • Once done with the above steps then serve or start the project.

Project Structure: It will look like the following.



Code Implementation:

app.module.ts: 

Javascript




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

app.component.html: 

HTML




<h1 style="color:green">
    GeeksforGeeks
</h1>
  
<mat-divider> </mat-divider>
  
<h5>One stop Solution for all CS subjects</h5>
  
<mat-divider> </mat-divider>
  
  
<p>
    The above horizontal line is displayed 
    due to the presence of mat-divider tag.
</p>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :