menu Angular Material Components Theming System: Complete Guide share Share

Angular Material Components Theming System: Complete Guide

# Overview In this course, you will learn what Angular Material Theming is and what are some recent changes to adhere to the new module system of SASS. Then, we will set up a project with Angular Material. We will then add a custom theme in it and understand some important mixins like `core`, `define-palette`, `define-light-theme` and we will apply custom theme to Angular Material components. And we will also learn how to use a pre-built theme. After setting up the theme, we will understand typography and also modify it for header tags (`

`, `

`, etc.) for the application. Next, we will create a dark theme using `define-dark-theme`. We will implement lazy loading for dark theme, so that it only loads when needed. After adding support for multiple themes, we will learn how to apply Angular Material’s theming to custom components. We will take an example of an `alert` component and apply themes to it. We will also learn about how to customize styles of Angular Material components. We will take the example of `MatButton` and add new variants for it. ## Angular Material UI Components The Angular team builds and maintains both common UI components and tools to help us build our own custom components. `@angular/material` is [Material Design]( UI components for Angular applications. Angular Material also provides tools that help developers build their own custom components with common interaction patterns. ### Angular Material’s Theming System In Angular Material, a theme is a collection of color and typography options. Each theme includes three palettes that determine component colors: primary, accent and warn. Angular Material's theming system comes with a predefined set of rules for color and typography styles. The theming system is based on [Google's Material Design]( specification. You can also customize color and typography styles for components in your application. ## SASS Basics Before moving ahead, It would be great if you have familiarity with [SASS basics](, including [variables](, [functions](, [mixins](, and [use]( ## New changes of SASS in Angular Material SASS introduced a new module system, including a migration from `@import` to `@use` in 2019. The [@use]( rule loads mixins, functions, and variables from other SASS stylesheets, and combines CSS from multiple stylesheets together. Stylesheets loaded by `@use` are called "modules". By switching to `@use` syntax, we can more easily determine what CSS is unused, and reduce the size of the compiled CSS output. Each module is included only once no matter how many times those styles are loaded. Angular Material v12 included a migration from `@import` usage to `@use` for all imports into the Angular Material SASS styles. They updated their code base for all styles with version 12. You can check out that [particular release]( for more information. This refactor of the theming API surface is easier to understand and read, helping developers like us take better advantage of this new module system.

at sign

Stay up to date

Subscribe to the newsletter to stay up to date with articles, courses and much more!

Terms & ConditionsPrivacy PolicyRefund Policy
X (Twitter)