Serengeti logo BLACK white bg w slogan
Menu

Angular Material Theming

Martin Jurić, Frontend Developer
24.02.2023.

Introduction

Angular Material is a popular UI library for Angular that provides a set of reusable, well-designed UI components. One of its powerful features is the ability to apply custom themes to the components, allowing you to change the look and feel of your application with just a few lines of code. In this blog, we'll take a deep dive into Angular Material Theming and learn how to use it in your own applications.

What is Angular Material Theming?

Angular Material Theming is a feature that allows you to apply a custom color palette to the components of the Angular Material library. You can either use one of the predefined themes (such as deeppurple-amber.css), or create your own custom theme. The theme is then applied globally to all Angular Material components in your application, giving you consistent and cohesive visual style.

How to Use Angular Material Theming

Using Angular Material Theming is quite simple. Here are the steps to follow:

Include the theme CSS file in your HTML file. You can find the theme CSS files in the @angular/material/prebuilt-themes folder.

image 17

Configure your application to use the theme by importing the MatPaginatorIntl module and adding the MAT_THEME_NAME constant to your NgModule imports.

image 18

And that's it! After taking just these two steps, you can start using Angular Material Theming in your application.

Pre-built themes

Angular Material provides several pre-built themes that you can use in your application. Here are some of the most commonly used themes: (Angular Material UI component library )

indigo-pink - this theme uses a deep indigo color as the primary color and a soft pink color as the accent color. This theme provides a bold and playful look well-suited for creative applications.

image 19

deeppurple-amber - this theme uses a rich deep purple color as the primary color and a warm amber color as the accent color. This theme creates a sophisticated and stylish look ideal for luxury or high-end applications.

image 20

pink-bluegrey - this theme uses a playful pink color as the primary color and a cool blue grey color as the accent color. This theme creates a light and playful look great for casual or friendly applications.

image 21

purple-green - this theme uses a regal purple color as the primary color and a fresh green color as the accent color. This theme provides a modern and sophisticated look well-suited for applications focused on growth, innovation, and sustainability.

image 22

Third-party Material Themes

Now that you are familiar with pre-built themes, there are also some third-party services providing themes that are easy to import and contain user friendly UI kits that don’t need a lot of coding. Here are some examples:

Material Design Lite (MDL) - this is a collection of CSS and JavaScript components that are compatible with Angular Material and follow the Material Design guidelines. They have a bunch of templates that you can use for your projects. (Material Design Lite (getmdl.io))

image 23

Material Kit - this is a responsive UI kit based on Angular Material and Google's Material Design guidelines. It provides a wide range of components and UI elements that can be easily customized to suit your needs. (Material Kit 2 by Creative Tim (creative-tim.com))

image 24

Materialize - this is a modern front-end framework based on Angular Material and Material Design. It provides a wide range of UI components, including forms, navigation and buttons are designed to look and feel great on all devices. The only problem with this framework is that it is not free, but quality isn’t always free, right? (Documentation - Materialize (materializecss.com) )

image 25

NG-Bootstrap - this is a collection of Angular components based on Bootstrap, a popular front-end framework. It provides a wide range of UI components, including forms, navigation and buttons designed to work well with Angular. There are no exact themes to show for this one as it is a framework for creating projects using the variety of the components listed in it. (Angular powered Bootstrap (ng-bootstrap.github.io))

image 26

Creating a Custom Theme

If you want to create your own custom theme, you can do it by defining a theme object and passing it to the createMuiTheme function from the @material-ui/core/styles package. Here's an example:

image 27

In this example, we define the primary and secondary colors of our custom theme. You can also specify other styles, such as typography, shape and spacing, to further customize the look and feel of your components.

Conclusion

In conclusion, Angular Material Theming is a powerful and versatile feature that allows you to easily customize the look and feel of your Angular Material components. Whether you choose to use one of the predefined themes or create your own custom theme, you can achieve a consistent and cohesive visual style for your application. Theming is simple to use and can be applied with just a few lines of code, making it an accessible and effective tool for improving the user experience of your Angular applications. So, give Angular Material Theming a try and see how it can enhance the design of your next project!

Let's do business

The project was co-financed by the European Union from the European Regional Development Fund. The content of the site is the sole responsibility of Serengeti ltd.
cross