Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Styling Angular Material datepicker

I’m trying to style my angular material date picker , However, it did not work by using many different approaches ( I am using Angular 17 and angular material 17.3.10). i saw many questions here being answered by using ::ng-deep , but it is deprecated now , so using this does not work:

:host ::ng-deep .mat-calendar {
  display: block;
  background-color: #b91212;
  color: var(--mat-datepicker-calendar-container-text-color);
  box-shadow: var(--mat-datepicker-calendar-container-elevation-shadow);
  border-radius: var(--mat-datepicker-calendar-container-shape);
}

Also , tried to use panelClass but that did not work either.
One thing to also mention that in Angular material Docs , styling is only provided for v19 .
Can you guys help me ? i’ll be grateful 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Targeting the internal elements of the Angular Material components is not recommended, see their theming docs. Instead, you should set values for their CSS variables.

Angular Material v19+

Angular Material v19 added an overrides SCSS API for each component, which allows customization of the appearance.
For example, to override the datepicker styles, use the following SCSS code:

@use '@angular/material' as mat;

// Customize the entire app. Change :root to your selector if you want to scope the styles.
:root {
  @include mat.datepicker-overrides((
    calendar-container-background-color: #b91212,
    // add more overrides here if needed ...
  ));
}

You can check the datepicker documentation for all possible values which you can override.

Angular Material v17 / v18

In case you are using an earlier version where this API is not available yet, the best solution is to directly provide values for their CSS variables:

// Customize the entire app. Change :root to your selector if you want to scope the styles.
:root {
  --mat-datepicker-calendar-container-background-color: #b91212;
  // add more variables here if needed ...
}

As soon as you update your app to Angular v19 or later, you should refactor the code and use the overrides mixins, as only those are officially supported.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading