How to set color of toggle buttons

matButtonToggle does not support the color property like matButton.

You can use the css classes .mat-button-toggle and .mat-button-toggle-checked to style the different states.

With material theming you can extract whichever individual palettes you need from the theme and apply the backgrounds default-contrast color to the text color to achieve optimal contrast with light or dark colors.

Here is a Stackblitz with your mat-button-toggle-group example: Stackblitz angular-t1k1x6

Theming used:

@import '~@angular/material/theming';

@include mat-core();

$app-primary: mat-palette($mat-indigo);
$app-accent:  mat-palette($mat-pink, A200, A100, A400);

$app-theme: mat-light-theme($app-primary, $app-accent);

@mixin mix-app-theme($app-theme) {
  $primary: map-get($app-theme, primary);
  $accent: map-get($app-theme, accent);

  .mat-button-toggle {
    background-color: mat-color($primary);
    color: mat-color($primary, default-contrast);
  }

  .mat-button-toggle-checked {
    background-color: mat-color($accent);
    color: mat-color($accent, default-contrast);
  }
}

// Include the mixin
@include mix-app-theme($app-theme);

Documents: Theming your Angular Material app


Customizing the presentation using your own theme SASS, as the other answer shows, is a great short-term solution and gives you a lot of power over the presentation. Ideally, this would become part of the core theme declarations, so that <mat-button-toggle-group color="primary"> (perhaps also <mat-button-toggle color="primary">) just works without additional steps.

If you want to make this simpler in the future, give a thumbs-up to this issue.


mat-button-toggle-group {
  box-shadow: none;
}

mat-button-toggle {
    border: 1px rgba(0,0,0,0) solid !important;
    margin-top: 5px !important;
    padding: 0 5px !important;
    z-index: 3 !important;
}

mat-button-toggle:hover {
    border: 1px #000 solid !important;
    background-color: #FFF !important;
    border-radius: 5px !important;
}

.mat-button-toggle-checked {
	  box-shadow: 0 0 30px #000 !important;
    border: 1px #000 solid !important;
    border-radius: 5px !important;
    background-color: #FFF !important;
}

.mat-button-toggle-input {
    background-color: none !important;
    padding-left: 32px !important;
}

if you only want to change the style of checked