by Sai gowtham

How to add fonts to a nuxt app

In this tutorial, we are going to learn about how to add custom fonts to a nuxt app that is created using create-nuxt-app.

Adding local fonts

  1. Open the nuxt app in your favorite code editor.

  2. Download the fonts locally and place them inside the assets folder.

  3. Create a new file called global.css inside the layouts folder and include the downloaded font by referencing the path.

global.css
@font-face {
    font-family: "Oxygen";
    src: local("Oxygen"),     url(~assets/Oxygen/Oxygen-Regular.ttf) format("truetype");}

html {
    font-family: "Oxygen";
}

In the above code, I have added an Oxygen font.

  1. Navigate to the nuxt.config.js file and add the global.css file inside the css array.
nuxt.config.js
css: [
    "~layouts/global.css",
],
  1. Now, this font is used by all pages in our nuxt app.

Adding Google fonts

We can also use google fonts (API) instead of local fonts by adding it to the link array inside our nuxt.config.js file.

nuxt.config.js
export default {
  head: {
    link: [
      { rel: "icon", type: "image/x-icon", href: "/favicon.ico" },
      {        rel: "stylesheet",        href: "https://fonts.googleapis.com/css2?family=Oxygen&display=swap",      },    ],
  },
}

Now, you can use this font inside your nuxt pages like this.

index.vue
<style>
html {
   font-family: "Oxygen";
}
</style>

or you can include it to all pages, by adding it to the layouts/default.vue file.

layouts/default.vue
<style>
html {
  font-family: "Oxygen";
}
</style>

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2021 (Beginner + Advanced)
JavaScript - The Complete Guide 2021 (Beginner + Advanced)
64,026 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)
152,857 students enrolled
48.5 hours of video content
View Course