To get started, add @nuxt/fonts
to your project:
npx nuxi@latest module add fonts
Or you can install it manually.
pnpm i @nuxt/fonts
Then, add it to the modules
in your nuxt.config
:
export default defineNuxtConfig({
modules: [
'@nuxt/fonts',
]
})
If you don't already have it in your .gitignore
, go ahead and add the .data
directory:
.data
You can now get started by adding a font-family
declaration to your CSS. ✨
<template>
<div>
Hello Nuxt Fonts!
</div>
</template>
<style scoped>
div {
font-family: Roboto, sans-serif;
}
</style>
That's it! Nuxt Fonts will detect this and you should immediately see the web font loaded in your browser. Read more about how it works.
@nuxt/fonts
by default only loads the normal/400 font-weight. See the configuration docs on how to change this default.If an error occurs during installation:
pnpm up @nuxt/fonts
npx nuxt@latest upgrade --force