Announcing: Theme Builder for Angular Material
Tags: angular, angularmaterial, webdev
Published: 2024-06-05 16:16:40

---
title: Announcing: Theme Builder for Angular Material
published: true
description: Build, preview and export themes for Angular Material 18
tags: angular,angularmaterial,webdevelopment
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69ssqo81hgxmlm6zzcwg.png
canonical_url: https://angular-material.dev/articles/angular-material-theme-builder
---

We are happy to say "Hello World" from our new tool called: "Theme Builder for Angular Material". You can visit it now at [themes.angular-material.dev](https://themes.angular-material.dev).

## What is it?

Theme builder is a tool for Angular developers who are using Angular Material 18 in their project. This tool allows you to build, preview and export themes for Angular Material.

You can also share themes simply by using a unique link with your team of developers or designers.

## How to use it?

First of all, create a project using Angular and Angular Material. You can jump to [modifying `define-theme` mixin](#modifying-the-define-theme-mixin) mixin if you have already created a project with custom theme.

```bash
npm i -g @angular/cli
ng new my-material-app --style scss --skip-tests --defaults
cd my-material-app
ng add @angular/material
```

And select answers as below:

```bash
? Choose a prebuilt theme name, or "custom" for a custom theme: Custom
? Set up global Angular Material typography styles? Yes
? Include the Angular animations module? Include and enable animations
```

### Modifying the `define-theme` mixin

Take a look at `src/styles.scss`. Notice the usage of `define-theme` mixin:

```scss
// Define the theme object.
$my-material-app-theme: mat.define-theme(
  (
    color: (
      theme-type: light,
      primary: mat.$azure-palette,
      tertiary: mat.$blue-palette,
    ),
    density: (
      scale: 0,
    ),
  )
);
```

We are going to make changes in above code to achieve customizations through CSS custom properties.

#### Add `use-system-variables: true`

Make changes in `color` and `typography` maps as below:

```scss
$my-material-app-theme: mat.define-theme(
  (
    color: (
      theme-type: light,
      primary: mat.$azure-palette,
      tertiary: mat.$blue-palette,
      use-system-variables: true, // 👈 Added
    ),
    typography: (
      use-system-variables: true, // 👈 Added
    ),
    density: (
      scale: 0,
    ),
  )
);
```

### Modifying `:root` selector

Next, add below mixins in `:root`:

```scss
:root {
  @include mat.all-component-themes($my-material-app-theme);
  @include mat.system-level-colors($my-material-app-theme); // 👈 Added
  @include mat.system-level-typography($my-material-app-theme); // 👈 Added
}
```

## Generating theme from Theme Builder

Now go to [themes.angular-material.dev](https://themes.angular-material.dev), modify colors as per your need and copy the CSS variables.

{% embed https://dev.to/shhdharmen/unpublished-video-3fnl-4ngj-temp-slug-282687?preview=b08c63086a8889c41c728f930600c9f3e6275960afac878bf69f0e624c483c245251f6d4798fc5ceb71c6bdca8df3a3a65248444641b5a6fab82db43 %}

### Using CSS variables

Now, create a new file at `src/styles/root.css` and paste all content in it. Simply import that file through `angular.json`'s `styles` property! Or any other dynamic way, such that `root.css` file is rendered in correct order to reflect all `--sys-*` variables.

```json
{
    "styles": [
        "src/styles.scss",
        "src/styles/root.css"
    ],  
}

```