Hi everybody and sorry my english.
I have created a nuxt.js project with Tailwind. I´d like to custom my font family, so I downloaded some font files from Google Fonts. I have been reading Tailwind docs, but i can´t understand where do i have to place the font files and how to config Tailwind for loading the files.
I´d be very gratefull if somebody could help me.
Using the font-face rule, we specify the font-family value of our custom font and then specify the path to the font file in our project via the src property. And that's it! We are now using a locally installed font in the project.
Visit Google Fonts and search for the specific font you like. Select the style variants from thin (100) to bold (900). Copy the import statement in between the style tags. Import the new font in the CSS file where you import tailwind classes, i.e., styles.
I'm assuming you're using the module @nuxtjs/tailwindcss.
First, you'll have to run npm run build
, so that tailwind files are created:
Create a folder fonts
under assets
and place the fonts you've downloaded.
Include your fonts in ~/css/tailwind.css
, as such:
@include font-face( KapraNeuePro, '~/assets/fonts/KapraNeueProFamily/Kapra-Neue-Pro-Regular', 400, normal, otf);
@include font-face( KapraNeuePro, '~/assets/fonts/KapraNeueProFamily/Kapra-Neue-Pro-Medium', 600, medium, otf);
etc.
tailwind.config.js
, and which configuration better suits your needs:
(the following one is a quick working example)module.exports = {
theme: {
fontFamily: {
sans: ["KapraNeuePro"],
serif: ["KapraNeuePro"],
mono: ["KapraNeuePro"],
display: ["KapraNeuePro"],
body: ["KapraNeuePro"]
},
variants: {},
plugins: []
}
};
font-family
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With