Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • AngularJS Tutorial
  • AngularJS Directives
  • AngularJS Functions
  • AngularJS Filters
  • AngularJS Examples
  • AngularJS Interview Questions
  • Angular ngx Bootstrap
  • AngularJS Cheat Sheet
  • AngularJS PrimeNG
  • JavaScript
  • Web Technology
Open In App
Next Article:
Angular Material Installation
Next article icon

Angular Material Installation

Last Updated : 31 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Angular Material is a popular UI framework for building user interfaces with the Material Design style, widely used by web developers around the world. It is a set of reusable UI components and guidelines for building web applications with the Material Design language, which is developed by Google. It is built on top of Angular, a popular JavaScript framework for building web applications, and provides a consistent look and feels across all platforms.

In this article, we will see the process of installing and setting up Angular Material in the project, along with understanding its basic implementation through the illustration.

Installation procedure for Angular Material: To get started, we'll need to have the Angular CLI installed on our local machine. If don't already have the CLI installed, you can install it by running the following command:

npm install -g @angular/cli

Once you have the Angular CLI installed, create a new Angular project by running the following command:

ng new my-project
Screenshot-2023-01-05-06423

Replace "my-project" with the name of your project. This will create a new Angular project with all the necessary files and dependencies.

Configuring the Project: Next, we'll need to install the Angular Material library and its dependencies. We can do this by navigating to the project directory and running the following command:

cd my-project
ng add @angular/material

We will be prompted to choose your prebuilt theme, and your preferences for the Angular animations module during the installation process.

This will install the Angular Material library and its dependencies, and also update your Angular project with the necessary configuration for using Angular Material components.

You can update the Angular Material configuration by adjusting the code in the angular.json file. By default, the following configuration was created:

angular.json:

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-project": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/my-project",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "my-project:build:production"
},
"development": {
"browserTarget": "my-project:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "my-project:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
}
}
}

Project Structure: This is a basic and common project structure, & the directory structure of our project (here, named 'my-project') will look like this:

Example 1: This article describes the basic implementation of Angular Material.

app.component.html:

HTML
<mat-card>     <mat-card-header>         <mat-card-title>             GeeksforGeeks         </mat-card-title>     </mat-card-header>     <mat-card-content>         <p>             This article describes the Angular Material              installation process in detail.         </p>     </mat-card-content> </mat-card> 

app.component.css:

CSS
mat-card-title {   color: green; }  mat-card {   text-align: justify;   border: 1px solid black;   width: 355px;   padding: 5px; } 

app.module.ts:

JavaScript
import { BrowserModule }      from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { MatCardModule }      from '@angular/material/card';  @NgModule({     declarations: [         AppComponent     ],     imports: [         BrowserModule,         MatCardModule     ],     providers: [],     bootstrap: [AppComponent] }) export class AppModule { } 

app.component.ts:

JavaScript
import { Component } from '@angular/core';  @Component({     selector: 'app-root',     templateUrl: './app.component.html',     styleUrls: ['./app.component.css'] }) export class AppComponent { } 

To run the project, type the following command in the terminal:

npm run start

Output:

Example 2: This is another example that illustrates the Angular Material Installation by implementing the Material Card.

app.component.html:

HTML
<mat-card>     <mat-card-header>         <mat-card-title>             <h1>GeeksforGeeks</h1>         </mat-card-title>         <mat-card-subtitle>             <h3>                   Angular Material Installation               </h3>         </mat-card-subtitle>     </mat-card-header>     <mat-card-content>         <p>             Angular Material is a UI component library             for Angular applications. It provides a set             of reusable UI components that are easy to             customize and integrate into your application.         </p>     </mat-card-content>     <mat-card-actions>         <button mat-button style="background-color: red;                                    color: white">             Like         </button>&nbsp;         <button mat-button style="background-color: blue;                                   color: white">             Share         </button>     </mat-card-actions> </mat-card> 

app.component.ts:

JavaScript
import { Component } from '@angular/core';  @Component({     selector: 'app-root',     templateUrl: './app.component.html',     styleUrls: ['./app.component.css'] }) export class AppComponent { } 

app.module.ts:

JavaScript
import { BrowserModule }      from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { MatCardModule }      from '@angular/material/card';  @NgModule({     declarations: [         AppComponent     ],     imports: [         BrowserModule,         MatCardModule     ],     providers: [],     bootstrap: [AppComponent] }) export class AppModule { } 

app.component.css:

CSS
p {   font-family: "Lato", sans-serif;   text-align: justify; }  .example-card {   max-width: 450px;   margin: 10px; }  mat-card-subtitle {   font-size: 18px; }  mat-card-title {   color: green;   font-size: 55px;   justify-content: center;   display: flex; } 

To run the project code, type the following command in the terminal:

npm run start

This will start the Angular Live Development server, to access your project, paste the following URL on any browser in your system:

http://localhost:4200/

Output:

In conclusion, Angular Material is a powerful UI framework that makes it easy to add professional-grade components to your Angular application. By following the steps outlined in this article, you can quickly and easily install and set up Angular Material in your project, and start using its wide range of components to build user interfaces that look and feel great. Whether you're a seasoned web developer or just starting out, Angular Material is a great choice for building modern, professional-grade user interfaces.

Reference: https://material.angular.io/guide/getting-started


Next Article
Angular Material Installation

P

phasing17
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • AngularJS
  • Technical Scripter 2022
  • Angular-material

Similar Reads

    Angular 7 | Installation
    To install Angular 7 on your machine you have to require the following things to be installed in your machine. Install Visual Studio Code IDE or JetBrains WebStorm.Install Node.jsUsing npm to install angular cli Follow the steps to set up an Angular 7 Environment: Step 1: Install Visual Studio Code
    2 min read
    Angular Material Icons
    Angular Material is a UI component library that is developed by Google so that Angular developers can develop modern applications in a structured and responsive way. By using this library, we can significantly increase an end-users user experience, thereby gaining popularity for our application. Thi
    5 min read
    What are angular Material Icons ?
    Angular Material is a UI component library which is developed by Google so that Angular developers can develop modern applications in a structured and responsive way. By making use of this library, we can greatly increase the user experience of an end-user thereby gaining popularity for our applicat
    3 min read
    Introduction to Angular Universal
    In the last few years, Angular become one of the most famous front-end framework to develop single page application. Most of the people think Angular only works on client-side but its partially true as there is one concept in Angular which explain some part of the application to be rendered at serve
    4 min read
    Angular Tutorial
    Angular is a powerful, open-source web application framework for building dynamic and scalable single-page applications (SPAs). Developed by Google, Angular provides a comprehensive solution for front-end development with tools for routing, form handling, HTTP services, and more.Designed for buildin
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences