Prerequisites
Before installing Angular Material, make sure you have:Node.js and npm
Install Node.js (which includes npm). Angular requires a current, active LTS, or maintenance LTS version of Node.js.
Automatic Installation (Recommended)
The easiest way to install Angular Material is using the Angular CLI’sng add command:
What ng add Does
The ng add command will:
Install Dependencies
Install Dependencies
- Adds
@angular/materialtopackage.json - Adds
@angular/cdk(Component Dev Kit) topackage.json - Adds
@angular/animationstopackage.json
Configure Theme
Configure Theme
You’ll be prompted to choose a prebuilt theme or set up a custom theme:
- Azure Blue - Indigo & Pink
- Rose Red - Pink & Indigo
- Magenta Violet - Purple & Green
- Cyan Orange - Deep Orange & Amber
- Custom - Set up an extensible custom theme
angular.json or a custom theme file will be created.Set Up Typography
Set Up Typography
You’ll be asked whether to apply global Angular Material typography styles:
- Yes - Applies Material Design typography across your entire application
- No - You can manually configure typography later
Add Fonts and Icons
Add Fonts and Icons
- Adds Roboto font to your
index.html - Adds Material Design icon font to your
index.html
Configure Global Styles
Configure Global Styles
Adds global CSS to
styles.css or styles.scss:- Removes margins from
body - Sets
height: 100%onhtmlandbody - Sets Roboto as the default application font
Manual Installation
If you prefer to install and configure Angular Material manually, follow these steps:Configure Animations
Add the Or if you’re using NgModules:
BrowserAnimationsModule to your application. Import it in your app configuration:app.config.ts
app.module.ts
If you don’t want animations, you can use
NoopAnimationsModule instead.Include a Theme
Including a theme is required to apply Material Design styles to your components.Add one of the prebuilt themes to your Available prebuilt themes:
angular.json:angular.json
azure-blue.cssrose-red.cssmagenta-violet.csscyan-orange.css
Installing Other Packages
Angular CDK Only
If you only need the Component Dev Kit (CDK) without Material components:Google Maps Component
To use the Google Maps component:- Get a Google Maps API key
- Load the Google Maps JavaScript API in your
index.html
YouTube Player Component
To use the YouTube Player component:Verify Installation
After installation, verify that everything is working by importing and using a component:app.component.ts
Next Steps
Quick Start
Build your first Material application
Theming
Customize your component appearance
Schematics
Generate components with Angular CLI
Components
Explore available components
Troubleshooting
Components have no styles
Components have no styles
Make sure you’ve included a theme. Check that your
angular.json includes a prebuilt theme or that your custom theme is being loaded.Animations not working
Animations not working
Verify that
BrowserAnimationsModule or provideAnimations() is included in your application configuration.Icons not displaying
Icons not displaying
Check that the Material Icons font is loaded in your
index.html. You can also use SVG icons with MatIconModule.Font not applied
Font not applied
Ensure the Roboto font is loaded in your
index.html and the global styles are configured correctly.