How To Add Google Font in Nuxt Application
Here in this article we will see how to add google font in nuxtjs 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 in your script tag.
If you want to add custom font or want to add a font locally in your nuxt project, check out our previous post here
How to get Google font link
Step 1 : First go-to fonts.google.com and search the fonts in the searcnh bar that you want to add.
Step 2 : After that select the font style you want example thin, regular or bold etc.
Step 3 : Once selected you will see the selected fonts list in the right hand side of your screen.
Step 4 : Copy the link given below in your screen. For example
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,900;1,300;1,500&display=swap" rel="stylesheet">
How To Add Google Font Link In your Nuxtjs Script Tag
To add the google font link (API) in your nuxt project , we have to add it in the link array inside the nuxt.config.js file
export default { head: { link: [ { rel: "icon", type: "image/x-icon", href: "/favicon.ico" }, { rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,900;1,300;1,500&display=swap", }, ], }, }
After adding it you can use it in any of your nuxt pages. For example in your index.vue page.
<style> html { font-family: "Roboto"; } </style>
Or, if you want to use the font globally just add it in your layout/default.vue page.
Related Posts
How to add common header and footer in Nuxt
Short post on how to add common header and footer component for all your pages in your nuxt application using layouts directory.
How to add external script tag in head in Nuxt
To add external javascript script in nuxt we have to add the script tag with src in the head() method.
Convert image to webp in nuxtjs | Image Optimization
To optimize an image in nuxt we have to use the @nuxt/image module. It can convert an image to webp format in nuxt application.
How to add custom static 404 error page in Nuxt ?
This article is about how to add a custom static 404 page in our nuxt application. 404 error page willbe the fallback page if a page is not found in the static site.
