Step-by-Step: Integrating Fonts in Nuxt.js and Vue.js Projects
Tags: vue, nuxt, javascript, webdev
Published: 2024-05-21 11:48:50


![Integrating Fonts in Nuxt.js and Vue.js Projects](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcsxc0339l23a47uih4z.jpg)

> Check [this post ](https://webcraft-notes.com/blog/stepbystep-integrating-fonts-in-nuxtjs-and-vuejs)in [my web notes](https://webcraft-notes.com/)!

Welcome to our guide on integrating fonts in Nuxt.js and Vue.js projects. Fonts are more than just text elements; they serve as the visual backbone of your application's design, greatly influencing user experience and interaction. In this article, we'll delve into the intricate world of fonts, exploring where to acquire them and how to seamlessly incorporate them into your latest Nuxt.js or Vue.js endeavors.

Choosing the right font is akin to selecting the perfect outfit for your app—it communicates personality, enhances readability, and ultimately shapes the overall aesthetic appeal. Whether you're aiming for a sleek modern look or a classic timeless vibe, the fonts you integrate play a pivotal role in achieving your design goals.

So, if you're ready to elevate your design game and captivate users with stunning typography, let's dive in!
## Where to get Fonts?
To find fonts we can simply search on the internet, there are a massive amount of services like [fontspace](https://www.fontspace.com/), [dafont](https://www.dafont.com/) or [1001fonts](https://www.1001fonts.com/) that are offering free and not free fonts. I suggest you use [Google Fonts](https://fonts.google.com/), that also offeres numerous variants of fonts and simple dashboard to help you find fonts you like. 
## How to add Fonts to my Project?
Vue.js and Nuxt.js have the same options for adding fonts to the new project. We will use Nuxt project to show fonts integration process, also we will use Google Fonts services. Google Fonts offeres two options so let's check both. 

**First**, implement fonts by using "embed code":

- choose the font you like, and press the button "get embed code";

- in the list of font versions (thin, regular, bold ...) chose those you need;

- copy links from the field;

- with Vue.js: open index.html file (in root or public folder), and paste those links directly to the head section.

With Nuxt.js: open nuxt.config.js, we need to add new links to the Nuxt config app object. Like this:

```
link: [
   { rel: 'preconnect', href: 'https://fonts.googleapis.com' },
   { href: 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet' },
]
```
That is it, we added fonts globally, and now we can use it where ever we need.
```
.roboto-thin {
  font-family: "Roboto", sans-serif;
  font-weight: 100;
  font-style: normal;
}

.roboto-light {
  font-family: "Roboto", sans-serif;
  font-weight: 300;
  font-style: normal;
}
```
**The second** option, download fonts and use them directly from our project:

- choose the font you like, and press the button "Download All";

- extract archived fonts into assets => fonts folder, for example. We have added fonts to our project and now we need to implement them globally;

- create a new CSS or SCSS file in the assets folder, and name it fonts;

- import downloaded fonts into this fonts file with "font-face";
```
@font-face {
  font-family: Roboto-Regular;
  src: url(../fonts/Roboto-Regular.ttf);
  font-display: swap;
}

@font-face {
  font-family: Roboto-Italic;
  src: url(../fonts/Roboto-Italic.ttf);
  font-display: swap;
}
```
- import CSS file into nuxt.config.js file:
```
css: [
    '@/assets/styles/styles.css',
],
```
or import CSS into main.js file if we are talking about Vue.js.

Great, we did it and we can use fonts in our project.

In conclusion, our journey through integrating fonts in Nuxt.js and Vue.js projects has equipped us with the knowledge and tools to enhance the visual appeal and user experience of our applications. Fonts serve as the backbone of design, influencing everything from personality to readability. Let your fonts speak volumes and leave a lasting impression on your audience. Happy coding!