Skip to main content
Angular Material

Angular Material Overview

Estimated Time: 3 hours | Difficulty: Intermediate | Prerequisites: Components, Forms, Accessibility
Angular Material is a comprehensive UI component library that implements Google’s Material Design. The Component Dev Kit (CDK) provides behavior primitives for building custom components. Think of Angular Material as two distinct layers. The CDK is like a chassis — it provides the mechanical behavior (drag-and-drop physics, focus management, scroll virtualization, overlay positioning) without any visual opinion. Angular Material is the body that sits on top — it adds Material Design styling to those behaviors. You can use the CDK without Material if you want custom-branded components that still have professional-grade behavior like keyboard navigation and screen reader support.
Practical decision: If your company has its own design system, use the CDK directly and skip Angular Material’s visual layer. If you need to ship fast and Material Design is acceptable, use Angular Material components as-is and customize via theming. Trying to make Material components look like a completely different design system (e.g., overriding 50+ CSS rules per component) is almost always more work than building on CDK from scratch.

Setup

Common gotcha: If you skip ng add and just npm install @angular/material, you will miss the theme setup, font imports, and animation provider. Your components will render but look completely unstyled — no colors, no elevation, no transitions. Always use ng add for the initial setup.

Modern Configuration


Core Components

Buttons & Indicators

Material provides several button variants, each designed for a specific level of visual emphasis. Think of it like typography: mat-button is body text (low emphasis), mat-raised-button is a subheading (medium emphasis), and mat-fab is a headline (high emphasis). Picking the right variant is not just aesthetics — it guides the user’s eye to the most important action on screen.

Form Controls

Material’s form fields are more than styled inputs — they handle the entire lifecycle of a form control: floating labels, hint text, error messages, prefix/suffix icons, and character counts. The mat-form-field wrapper is what ties all of these together. One important design choice: always use appearance="outline" for forms where users enter data (it provides the clearest affordance), and reserve appearance="fill" for filter bars or search inputs where density matters more.

Data Table

MatTable is one of Material’s most powerful components, but also one of its most misunderstood. The key insight: MatTableDataSource is not just a wrapper around an array — it provides built-in filtering, sorting, and pagination that work out of the box when you wire up the corresponding directives. For most CRUD tables, you will never need to write custom filter or sort logic.
Practical tip: Use MatTableDataSource for tables with fewer than 1,000 rows. For larger datasets, use server-side pagination and sorting instead — pass the parameters to your API and let the database handle the heavy lifting. Client-side sorting of 10,000 rows will freeze the UI for hundreds of milliseconds.

Dialogs & Overlays

Dialogs are one of the most over-used patterns in web apps. Before reaching for a dialog, ask: “Could this be inline?” Confirmation for a delete? Inline. Editing a single field? Inline. A multi-step wizard that needs the user’s full attention? That is a dialog. The rule of thumb: dialogs are for actions that need isolation from the rest of the page — they force a decision before the user can continue.

CDK Features

Drag and Drop

CDK’s drag-and-drop system handles the physics (momentum, reorder animation), accessibility (keyboard reordering), and cross-container transfers. You provide the data model and the visual template — the CDK handles the rest. The most important concept is cdkDropListGroup: it tells the CDK that multiple drop lists are connected, enabling items to move between them (like a Kanban board).

Virtual Scrolling

Virtual scrolling is the CDK’s answer to the “render 10,000 items without crashing the browser” problem. Instead of creating DOM nodes for every item (which would mean 10,000+ elements in the DOM), it only renders the items visible in the viewport plus a small buffer. As the user scrolls, old items are recycled and new ones are created. The result: a list of 100,000 items feels just as smooth as a list of 20.
Key constraint: Fixed-size virtual scrolling requires that every item has the exact same height (specified via itemSize). If your items have variable heights, you need the experimental autosize strategy, which is significantly more complex and less performant. Design your list items to be fixed-height whenever possible.

Overlay & Portal

The CDK Overlay system is what powers every Material popup — dialogs, tooltips, select dropdowns, menus. It solves two hard problems: positioning (the dropdown should appear below the trigger, but flip above if there is not enough room) and z-index management (overlays should stack in creation order without you hardcoding z-index values). If you are building any custom popup component, use the CDK Overlay instead of rolling your own — you will avoid dozens of edge cases around scroll positioning, viewport boundaries, and backdrop handling.

Theming


Best Practices

Import Only What You Need

Import individual modules to minimize bundle size

Use CDK for Custom Components

Build on CDK primitives instead of from scratch

Follow a11y Guidelines

Material components are accessible by default - don’t break them

Customize via Theming

Use Sass theming instead of CSS overrides

Next: PWA & Service Workers

Build offline-capable Progressive Web Apps with Angular