by Sai gowtham

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

  1. Open the angular app in your favorite code editor.
  2. Create a new folder called fonts inside the assets folder.
  3. Download the fonts locally and place them in the fonts folder.
  4. 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.

style.css
@import url('https://fonts.googleapis.com/css2?family=Oxygen&display=swap');

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course