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 your 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)
26,545 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)
221,520 students enrolled
44 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
114,575 students enrolled
21 hours of video content
View Course