Angular-Material 2 Theme Tutorial

Recently, the Angular 2 version of angular-material from Google received the long-await theming options. In contrast to the JavaScript theming from angular-material v1 they opted for a powerful mixin driven SCSS theme.

Kyle Ledbetter
Covalent-UI
3 min readOct 24, 2016

--

Choosing a Material Design color palette

So many wonderful tools to help you on your color quest

If you use the official Material Design palette (which you should), you’re able to use all kinds of free color tools & apps on the web! Here are some of my favs:

theme.scss

In the /src directory of your ng2 app simply add this theme.scss:

That’s it! 7 lines of code to theme your entire Angular-Material 2 app!

Select your primary & accent colors

To edit the theme you simple swap our the orange & light-bluefrom that code snippet and insert your two colors. You can also adjust the hue (the numbers) to a lighter or darker shade, covered in all Material palette docs & apps. In this example I change to green & light-blue:

Notice that the hue you select (A400 here) will automatically change the white text to dark text if necessary.

Dark Theme

To swap over to a dark theme simply change this one line:

Angular-Material2 Dark Theme

Using Color Mixins for custom styles

Angular-Material2 uses a utility scss file, styles.scss, which like theme.scss is located in /src and automatically compiles. By simply importing the theme.scss into styles.scss you can tap into the color mixins like so:

We use this handy little style to color the active icon:

Accent colored active icon

Also notice the use of the dynamic contrasting color for the icon, which knows to turn white in this example with the dark hue of blue.

You can reference the available colors from the _palette.scss in Angular-Material2’s core styles.

Test this out for yourself!

My demo screenshots and code put the theme to use in Covalent, Teradata’s open-source Angular-Material2 UI Platform.

--

--

Kyle Ledbetter
Covalent-UI

VP of Design at Credo AI — Former UX leader for Teradata, eBay, MicroStrategy and Sears Holdings.