Full answer
Angular Material is the official component library. It follows Google's Material Design and is built on the Angular CDK (the Component Dev Kit, which holds behaviour such as overlays and accessibility helpers).
Set-up: ng add @angular/material installs the packages, adds a theme to styles.scss or styles.css, and adds the Roboto font and icon font links. Then import only what each component needs. Every Material piece is a standalone directive or component:
MatButtonfor<button mat-button>andmat-flat-button.MatFormField,MatLabel,MatError, andMatInputfor text fields.MatCard,MatToolbar,MatIcon,MatTable,MatPaginator,MatDialog,MatSnackBar,MatSelect,MatCheckbox, and more.
Forms: mat-form-field wraps a native input with the matInput directive. It works with reactive forms and ngModel. It displays mat-error when the control is invalid and touched.
Services such as MatSnackBar (small messages) and MatDialog (modals) are injected and opened from code. They use the CDK overlay.
Theming. Angular Material 3 (the current design system) uses a Sass theme API. In a global style file you call mat.theme((color: (...), typography: ..., density: 0)) for a base theme, and the components read CSS variables such as --mat-sys-primary. To change one component, set its documented CSS variables. Avoid ::ng-deep overrides, which break when the library changes its internal markup.
Good habits: import components individually (this keeps the bundle small), keep accessibility features on, and check the version table: Material major versions follow the Angular major version.
import { Component, inject } from '@angular/core';
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-subscribe-card',
imports: [ReactiveFormsModule, MatCardModule, MatFormFieldModule, MatInputModule, MatButtonModule],
template: `
<mat-card>
<mat-card-header>
<mat-card-title>Weekly newsletter</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-form-field appearance="outline">
<mat-label>Email</mat-label>
<input matInput type="email" [formControl]="email" />
@if (email.hasError('required')) {
<mat-error>Email is required</mat-error>
} @else if (email.hasError('email')) {
<mat-error>Enter a valid email</mat-error>
}
</mat-form-field>
</mat-card-content>
<mat-card-actions>
<button mat-flat-button [disabled]="email.invalid" (click)="subscribe()">Subscribe</button>
</mat-card-actions>
</mat-card>
`,
})
export class SubscribeCardComponent {
private readonly snackBar = inject(MatSnackBar);
readonly email = new FormControl('', { nonNullable: true, validators: [Validators.required, Validators.email] });
subscribe(): void {
this.snackBar.open(`Subscribed ${this.email.value}`, 'Close', { duration: 3000 });
}
}Angular 20.3 with Angular Material 20.2, strict template check passes. Add the theme with `ng add @angular/material` before running it.
Key points
- `ng add @angular/material` sets up the packages and theme.
- Import each Material component or directive into the component that uses it.
- Services like `MatSnackBar` and `MatDialog` open overlays from code.
- Theme with the Sass API and CSS variables. Avoid `::ng-deep`.
Common mistakes
- Importing nothing and wondering why `<mat-form-field>` is an unknown element.
- Overriding internal classes with `::ng-deep`, which breaks on upgrade.
- Using a Material version that does not match the Angular major version.
Follow-ups
- What is the Angular CDK and how does it relate to Material?
- How would you create a custom theme colour?
- How do you show validation errors in a `mat-form-field`?
Tips
- Mention the CDK relationship. It shows you know what is under the library.
- Describe theming with CSS variables, not class overrides.
- Say you import per component for bundle size.
Evaluation rubric
- Knows the set-up command and per-component imports.
- Uses form field and snack bar correctly.
- Understands theming and version alignment.