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.