How would you define custom primary and accent colors for an Angular Material theme?
Short answer
You define color palettes using Material's color definition functions, choosing specific colors for your primary and accent roles, then pass these into your theme definition, which Angular Material uses to generate consistent colors across every component automatically.
Advertisement
AModel answer
You define color palettes using Material's color definition functions, choosing specific colors for your primary and accent roles, then pass these into your theme definition, which Angular Material uses to generate consistent colors across every component automatically.
$my-primary: mat.define-palette(mat.$indigo-palette);
$my-accent: mat.define-palette(mat.$pink-palette);
$my-theme: mat.define-light-theme((
color: (primary: $my-primary, accent: $my-accent)
));Real-world example
A travel booking app defines a custom blue and orange theme matching their brand colors, and every Material button, checkbox, and progress bar throughout the app automatically reflects those exact brand colors.
Likely follow-ups
- How do you create a custom color palette instead of using one of the predefined ones?
- What is the difference between the primary, accent, and warn color roles?
Related topics