How to add fonts to an Angular app
In this tutorial, we are going to learn about how to add custom fonts to an angular app that is created using angular cli.
Adding local fonts
-
Open the angular app in your favorite code editor.
-
Create a new folder called
fonts
inside theassets
folder. -
Download the fonts locally and place them in the
fonts
folder. -
Open your
style.css
file and include the font by referencing a path.
@font-face {
font-family: "Oxygen";
src: local("Oxygen"), url(./assets/fonts/Oxygen/Oxygen-Regular.ttf) format("truetype");
}
Here I added a Oxygen
font.
Now, you can use this font inside the components css files like this.
.container{
font-family: "Oxygen", Arial, Helvetica, sans-serif;
font-size: 20px;
}
Adding Google Fonts
Similarly, you can also add google fonts (api) instead of local fonts using the @import
rule.
@import url('https://fonts.googleapis.com/css2?family=Oxygen&display=swap');