DEV Community

WebCraft Notes
WebCraft Notes

Posted on • Originally published at

Step-by-Step: Integrating Fonts in Nuxt.js and Vue.js Projects

Integrating Fonts in Nuxt.js and Vue.js Projects

Check this post in my web notes!

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, dafont or 1001fonts that are offering free and not free fonts. I suggest you use Google Fonts, 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: '' },
   { href: ',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' },
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode
  • import CSS file into nuxt.config.js file:
css: [
Enter fullscreen mode Exit fullscreen mode

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!

Top comments (0)