Setup before using the Custom Font
Step 1: In the folder src/assets
create a new folder fonts
so the new path looks like src/assets/fonts
.
Step 2: Place your custom font .ttf file inside this src/assets/fonts
so the new path looks like src/assets/fonts/custom_font.ttf
.
Step 3: Now in the folder fonts
create a new .css file such as font-file.css
so now the path looks like src/assets/fonts/font-file.css
. Inside this file write this,
@font-face {
font-family: "my_custom_font";
src: url("./custom_font.ttf") format("opentype");
}
After three steps this is how your directory structure should look like,
src -
|
- ... //other folders
|
- assets // assets folder
|
-fonts // fonts folder
|
-font-file.css //.css file
|
-custom_font.ttf //.ttf file
Step 4: Go to your angular.json
file and under the very first options:{}
attribute you will have styles:[]
. In this paste the full path to your font-files.css
such as
"options": {
...,
"styles": [
"src/styles.scss",
"src/assets/fonts/font-file.css" //the path to your font-file.css which we defined earlier in step3
]
}
Using Custom Font
Now you can easily use the newly added custom font such as,
body {
...
font-family: 'my_custom_font', 'arial', sans-serif;
}
assets
– Grizassets
section of theangular.json
file, then you can just reference them in css with@font-face
, as suggested in the answer below and here: #49879488 – Vaticide