Integrating latest Material Design Web components in Angular

In this quick tutorial, we will learn how to integrate @material/web components with example of buttons in Angular.

20th October, 2023 — 4 min read

Open in StackBlitz
Photo by Milad Fakurian
> In this quick tutorial, we will learn how to integrate @material/web components with example of buttons in Angular. Before we jump to coding, let's understand what is Material Design, Web Components and Material Web 1.0. ## Material Design Material Design is a design system built and supported by Google designers and developers. Guidelines for building Material apps and components are published on []( The latest version, Material 3, enables personal, adaptive, and expressive experiences – from dynamic color and enhanced accessibility, to foundations for large screen layouts and design tokens. ## Web Components [Web components]( are custom HTML elements with encapsulated styles and behavior. They work across many different frameworks (such as Angular, Lit, React, Vue, and Svelte) as well as web environments (such as Eleventy, Wordpress, and Ruby on Rails). ## Material Web 1.0 [Material Design team]( recently announced the release of Material Web 1.0. [![announcement tweet](]( Material Web is Google’s component library for building applications that work in any web framework. Each component has been reviewed by Material 3 designers and accessibility engineers for use in production. ### What's in 1.0? - ⚙️ 19 components, including buttons, checkboxes, chips, text fields, selects, and dialogs - 🎨 CSS theming for dynamic color, fonts, and Material tokens - ♿️ Accessibility for screen readers and high contrast - 📖 Documentation and guides - 📋 `` element support - 🏗️ Cross-framework support, including Lit, React, Vue, and Svelte - 🤖 Basic Lit SSR support - 👏 Fewer breaking changes ### Components You can check all the components and their respective documentation at []( ### Tech Stack Material Web components are generated using [Lit]( Lit is a simple library for building fast, lightweight web components. ## Usage in Angular For this tutorial, we will focus on implementing button components from `@material/web` in Angular application, let's get started! ### 1. Creating the application ```bash ng new material-web-ng --defaults --minimal --standalone ``` ### 2. Install `@material/web` ```bash npm install @material/web ``` ### 3. Add Material Design buttons Now, go to `src/app/app.component.ts`, and remove all content from `template` and remove `styles`. As we are going to use non-Angular components, we will need to add `CUSTOM_ELEMENTS_SCHEMA` in `schemas`. For starters, we will simply try to add [Elevated buttons]( in our application. To do so, we will write an `import` statement from `@material/web/button/elevated-button` and simply put `` in template. ```typescript import { CUSTOM_ELEMENTS_SCHEMA, Component } from "@angular/core"; import { CommonModule } from "@angular/common"; import "@material/web/button/elevated-button"; @Component({ selector: "app-root", standalone: true, imports: [CommonModule], schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` Elevated ` }) export class AppComponent {} ``` Let's look at the output: ![embedded video]( Congratulations! You just added your very first Material Design Web Component in your Angular application! ### 4. Fixing fonts At this point, your button works fine. But, you will notice that fonts are not rendered as expected. It's because we haven't loaded the fonts required by Material Design Web Components. Let's add `Roboto` fonts in `` of `src/index.html` file: ```html ``` Now your button will look perfect! ![embedded video]( With the similar approach, you can add other variants of buttons, like filled, text, filled-tonal and outlined. ## Conclusion We learned what is Material Design and components. And then we integrated `@material/web`'s Elevated button in the Angular application. I hope this quick tutorial will help you integrate latest guidelines of Material Design in your Angular applications. The code is available on GitHub at [Angular-Material-Dev/material-web-ng]( ## Live Playground
Dharmen Shah
Written by Dharmen Shah

I have around 8+ years of experience in IT industry. I have got opportunity to work at different companies with different technologies, mostly focused on Front-end, like Angular, React, Next, vanilla web stack (HTML, CSS, JavaScript).

You can find me on Twitter, Linkedin and Github.

Discuss online

Share this article

Read more

View all articles

Learn more

View courses page

Support Free Content Creation

Contributions & Support

Even though the courses and articles are available at no cost, your support in my endeavor to deliver top-notch educational content would be highly valued. Your decision to contribute aids me in persistently improving the course, creating additional resources, and maintaining the accessibility of these materials for all. I'm grateful for your consideration to contribute and make a meaningful difference!

Don't miss any update

Stay up to date

Subscribe to the newsletter to stay up to date with articles, courses and much more!

Angular Material Dev

Angular Material Dev is one place stop for developers to learn about integrating Material Design in Angular applications like a pro.

Find us on X (Twitter) and LinkedIn