Angular - Add Custom Font

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

commit fe1167b · authored · 1 min read

Angular - Add Custom Font

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.

local graph · open full graph

"Angular - Add Custom Font" is connected to the topics Angular. Angular #angular Angular - Add Custom Font

webmentions · 1 mention

  • David Auza · Aug 14, 2020 · mention

    I love this kind of tutorials, that goes directly to the point! Angular - Add Custom Font abhith.net/blog/angular-a… #angular via @AbhithRajan

comments

loading discussion…