DEV Community

WebCraft Notes
WebCraft Notes

Posted on • Originally published at webcraft-notes.com

5 1

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: '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' },
]


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;
}

- import CSS file into nuxt.config.js file:
Enter fullscreen mode Exit fullscreen mode

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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay