Add dark mode custom theme - @angular/material

richiepee

Phinehas Alabi

Posted on April 1, 2023

Add dark mode custom theme - @angular/material

Lets begin with the installation process after then properly configuring the custom dark team in our application.

ng add @angular/material 
Choose a prebuilt theme name, or "custom" for a custom theme: (Use arrow keys)
> Indigo/Pink        [ Preview: https://material.angular.io?theme=indigo-pink ]
  Deep Purple/Amber  [ Preview: https://material.angular.io?theme=deeppurple-amber ]
  Pink/Blue Grey     [ Preview: https://material.angular.io?theme=pink-bluegrey ]
  Purple/Green       [ Preview: https://material.angular.io?theme=purple-green ]
  Custom
Enter fullscreen mode Exit fullscreen mode

selected Custom

? Choose a prebuilt theme name, or "custom" for a custom theme: Custom
? Set up global Angular Material typography styles? (y/N) y
Enter fullscreen mode Exit fullscreen mode
? Set up browser animations for Angular Material? (Y/n) y 
Enter fullscreen mode Exit fullscreen mode

Now to use the dark theme, please follow the below syntax:

$Products-theme: mat.define-dark-theme((
  color: (
    primary: $Products-primary,
    accent: $Products-accent,
    warn: $Products-warn,
  )
));
.dark-theme{
  @include mat.all-component-themes($Products-theme);
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
richiepee
Phinehas Alabi

Posted on April 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related