How To Add Font Locally In Nuxt App

featured Image

In this tutorial, we will learn the step-by-step process of how to add a custom google font locally in your nuxtjs application. You can either use a premium font or you can just use any free google font that you like.

We will be using @font-face css property to add the font, it allows you to load custom fonts on your website. Once it is added to your CSS file it instructs the browser to download the font file from where it is hosted.

Download Font from google font website

First, get the font family you want to use in your nuxtjs project from fonts.google.com and then download it to your computer.

Note: You can get fonts from other sources or sites that you want.

Add the custom font in Nuxt Application

To add the custom font, follow the steps:

Step 1: Open your nuxt app in your favourite code editor.

Step 2: Now copy-paste the downloaded font file into the assests folder of the project directory.

Step 3: Now create a global stylesheet file eg: global.css and add the font as given below:

global.css

@font-face {
  font-family: 'MyWebFont';
  src: url('webfont.ttf')  format('truetype'),
}

Step 4: Once you have added the code to your CSS file, add the following line in your nuxt.config.js

css: [
    "~layouts/global.css",
],

Step 5: Now you can use the font anywhere in your project.

<style>
    body {
    font-family: 'MyWebFont', Fallback, sans-serif;
    }
</style>

Related Posts

featured Image

How To Add Robots.txt in your Nuxtjs Application

Here in this article, we will see how to add a robot.txt file in our nuxtjs application after it is built or generated before deployment. Before learning the steps to…

Read more
featured Image

How To Add Google Font in Nuxt Application

Here in this article we will see how to add google font in your nuxtjs project/application. The process is really simple you just have to import the google font link…

Read more
featured Image

How to generate sitemap for dynamic routes in nuxtjs application

Here in this article, we will learn to create sitemaps for dynamic routes in our nuxtjs application. It is not so easy to create the sitemaps easily with dynamic routes…

Read more