For the Angular Material Slider how do we style the track foreground, background, and width of the track and also the thumb fill color and thumb border color and width?
There is an answer here regarding styling the Angular Material Slider, however Angular Material has updated the DOM structure and the CSS classes to conform to the new Material Design Spec, so the styles no longer apply.
Here’s a Stackblitz for Angular 15 with an attempt to apply the styles from the SO answer.
2
Answers
For most of the stuff, you can just overwrite the css variables.
Apply a class to your slider:
And overwrite some of the variables used for styling:
I’m sure they’re all listed in docs somewhere, but I didn’t bother looking for them. Just inspecting the DOM using developer tools proved to be enough for simple changes.
Regarding the thumb border – by the material guideline, the border is the same color as the fill, so you’ll have to do more than changing the css variable. And since thumb is it’s own component, you will have to either use style piercing using
::ng-deep
or place the styles in the global styles.scss file.Working stackblitz with some random overwrites here.
Those are the CSS selector to directly customize every part of the new Angular Material 15 Slider:
This is the StackBlitz