angular

Angular - Add Custom Font

A short article about how to add custom font files to your Angular projects.

Abhith Rajan
Abhith RajanNovember 12, 2019 · 2 min read · Last Updated:

To add custom fonts to your Angular project, put the font files under src.

Here I am following the folder pattern which I found on ABP Zero boilerplate.

In my case src > assets > fonts > fontname > font-files (.woff).

Then create a CSS file, src > assets > fonts > fonts-fontname.css.

And on the CSS, add the font-face referring to our new font-flies, an example is given below.

@font-face {
  font-family: "fontname";
  src: url("./fontname/fontname.woff");
}

@font-face {
  font-family: "fontname-Medium";
  src: url("./fontname/fontname-medium.woff");
}

@font-face {
  font-family: "fontname-Light";
  src: url("./fontname/fontname-light.woff");
}

Once the CSS file is ready, now we have to include that too in the angular build. To do that, update the angular.json to have references to our new CSS file like in below example,

{
 ...
  "projects": {
    "project-name": {
     ...
      "architect": {
        "build": {
          ...
          "options": {
            ...
            "styles": [
              ...
              "src/assets/fonts/fonts-fontname.css",
              ...
            ],
            ...
          },
          ...
        },
        ...,
        "test": {
          ...
          "options": {
            ...
            "styles": [
              ...
              "src/assets/fonts/fonts-fontname.css",
              ...
            ],
            ...
          }
        },
        ...
      }
    },
}

Note: the above code is tried and tested on Angular 8

Once we updated the angular.json, start a new build and see the new font applied in the places where it is used.

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub


Abhith Rajan

Written byAbhith Rajan
Abhith Rajan is a software engineer by day and a full-stack developer by night. He's coding for almost a decade now. He codes 🧑‍💻, write ✍️, learn 📖 and advocate 👍.
Connect

Webmentions

Is this page helpful?

Related VideosView All

Angular v19 Developer Event

Related StoriesView All