Тёмный

Using Fonts in Next.js (Google Fonts, Local Fonts, Tailwind CSS) 

Lee Robinson
Подписаться 55 тыс.
Просмотров 153 тыс.
50% 1

Learn how to use the new & improved font optimization in Next.js 13, for both local and remote fonts from Google. @next/font automatically self-hosts your font files (for better privacy) and reduces layout shift by automatically generating a fallback font. It's pretty neat!
Learn more: nextjs.org/docs/basic-feature...
#nextjs #react

Наука

Опубликовано:

 

15 ноя 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 205   
@caleblovell
@caleblovell Год назад
Wow, this looks amazing. I hate seeing the CLS from font fallbacks on sites. Now I want to upgrade to Next 13 just for this!
@mmsrp
@mmsrp 10 месяцев назад
On the OFFICIAL DOCS they point to this, then: *Your project has `@next/font` installed as a dependency, please use the built-in `next/font` instead.*. Please update the docs or pin an updated comment here.
@maxproske1950
@maxproske1950 Год назад
Thanks Lee for putting out these high value-per-square-minute videos. Getting to watch in-depth explanations of new and experimental features early makes me feel part of the Next.js community. Random question, can `@next/font/local` be used in combination with `turbo`?
@leerob
@leerob Год назад
I believe if you start from `npx create-next-app@latest --example with-turbopack` and then add `@next/font/local`, it should work - I haven't verified myself, though. Note this uses Tailwind CSS.
@faizanahmed9304
@faizanahmed9304 Год назад
Thank you Lee for in depth explanation!
@petter9078
@petter9078 Год назад
I love your channel. Ended up so many times back here!
@phucnguyen0110
@phucnguyen0110 Год назад
Cool glasses, Lee xD And yes, I was able to implement the same thing here on the video through reading the docs - really lovely to have the native support from Next for sure. Not really related to Next 13 - but is there a plan to support Analytics out of the box for other frameworks than Next/Nuxt/Gastby as of right now?
@k2p11
@k2p11 Год назад
Wow, thanks this video, Lee! So helpful.
@TeleRocker11
@TeleRocker11 6 месяцев назад
Thanks Lee, another reason to love Next.js!
@mikesoertsz222
@mikesoertsz222 8 месяцев назад
What about if we want to load a secondary font as well? I've not seen an explanation of that anywhere. Good design usually has 2 brand fonts + web-safe fonts.
@skyhigheagleer6
@skyhigheagleer6 3 месяца назад
Load them in without next/font and use your own preload tags
@hynekss8618
@hynekss8618 Год назад
This is neat! It works like a charm right off the bat.
@glusa8
@glusa8 Год назад
Thanks for the video! So intrigued how you move your cursors seamlessly. And the cursor isn’t blinking! Are you using some kind of extension?
@official.mhm13
@official.mhm13 Год назад
Thanks for detailed explanation Lee Rob ❤️
@noureddinbakir6065
@noureddinbakir6065 Год назад
Love your work man, keep it up :)
@keenanreed5341
@keenanreed5341 Год назад
Simple and to the point. Thanks!
@_ash64
@_ash64 Год назад
Thank you so much, this is a very quality channel!
@josepedro3135
@josepedro3135 Год назад
Awesome video! Helped a lot, Thank you!
@Chris-hr8lt
@Chris-hr8lt 2 месяца назад
the tailwind part was so hard to find, thanks a lot for the video
@joseandkris
@joseandkris Год назад
The only thing that bothers me here is 2x `main` tag, suggesting non-semantic html. + extra html uneeded tag. Also, what if I need 2 or more fonts loaded?
@charliegunthers
@charliegunthers Год назад
thanks. i felt like an absolute dummy trying to do this reading from the nextjs docs
@whyfoo
@whyfoo 10 месяцев назад
well explained ! awesome feature!!
@Gelliny
@Gelliny Год назад
Thank you, this was really helpful.
@appstuff6565
@appstuff6565 6 месяцев назад
Thanks for this Lee!
@acidhauss7018
@acidhauss7018 Год назад
Awesome video, thanks for the upload
@nbo304
@nbo304 9 месяцев назад
This is great but how do i use several different fonts? for example, the title of my hero section uses a different font than the rest of the app. Every tutorial talks about only applying one font to the entire page.
@zenovak5177
@zenovak5177 2 месяца назад
Dont apply fonts to whole app at the app page via the main tag, instead, import them as the tutorials shown, and apply them selectively on your choosen elements.
@user-ik7rp8qz5g
@user-ik7rp8qz5g Год назад
Awesome, keep it up. We need more tutorials like this for other features. If my app uses variable font, but only specific weights (400, 500), is there totally no need to specify them? For when variable fonts are unsupported for some reason
@kozie928
@kozie928 Год назад
If you only need 2 weights, it may be worth checking the network tab to see if the variable font isn't bigger than the two fixed weights. I think in most cases, sizewise, variable fonts are worth if you'd use 3+ fixed weights.
@doylemichael
@doylemichael Год назад
So how do you add multiple fonts to an app directory? I want to have two different google fonts globally accessible on my site
@venicebeachsurfer
@venicebeachsurfer 3 месяца назад
... and of course, no reply from Lee. It's like these NextJS guys think everyone builds hello world apps....
@sjc5
@sjc5 Год назад
After looking through the docs, it looks like Arial and Times New Roman are the only fallback options? Courier for monospace would be nice as well.
@mmd1dev
@mmd1dev 8 месяцев назад
Great Lee thanks for the video 👏👏
@satindar31
@satindar31 Год назад
Just a heads up, if you created the project with the latest flag, next font is automatically installed so no need to run npm i @next/font :)
@Immigrantlovesamerica
@Immigrantlovesamerica Год назад
yeah, I noticed that! So cool.
@daryllreillo1646
@daryllreillo1646 10 месяцев назад
nice :)
@jggabayno
@jggabayno Год назад
Does RTK still makes sense with NextJS 13 app directory? or any state management you suggest to be use?
@chrisb.8441
@chrisb.8441 10 месяцев назад
Great video! Thank you
@hugosimoes6332
@hugosimoes6332 10 месяцев назад
Thanks, you helped a lot
@Morimove
@Morimove 3 месяца назад
i landed here from official next js documentaion. btw i already watched it and again i am here.
@EliteFailure
@EliteFailure Год назад
For someone who just started learning next: I don't get what exactly is considered being simple here, or what the real advantage is?! Classic local hosting of the the fonts is easy, and specifying a base font in the CSS (especially with a CSS framework like tailwind or bootstrap) is way more convenient than this orgy. What am I missing?
@icewolfy1
@icewolfy1 Год назад
Lets say only certain components need this font, how would you reference the font family from within those components? Lets say you are using sass, index.module.scss. The font-family name generated seems to include some numbers so I'm not sure how to use it from certain components
@codinginflow
@codinginflow Год назад
From the docs: -Call the font loader function in one shared file -Export it as a constant -Import the constant in each file where you would like to use this font I guess React context would also work
@DomBarker
@DomBarker 2 месяца назад
thanks! was having issues with mobile safair but this fixed
@codinginflow
@codinginflow Год назад
Is there any estimate when the new app directory will become stable and the default?
@metink516
@metink516 Год назад
hi thank you for how to video. I want to ask. Why didn't they put the next/font install code in the documentation?
@henriqpohl
@henriqpohl 6 месяцев назад
Hi, helpful video, but I still have a problem, when I declare everything in my "layout.tsx" I cant use in another pages so I need to redeclare again, thats correct?
@JuangaSdvsf
@JuangaSdvsf Год назад
Thanks for the explanation. What if instead of using tailwind I want to use sass?
@zindev
@zindev Год назад
Thank you Lee!
@mr.random8447
@mr.random8447 Год назад
Isn't self-hosting bad for performance? Pretty much if we use @next/font we have to deploy on Vercel to get that CDN performance?
@Kingdutch01-Eng
@Kingdutch01-Eng Год назад
❤❤
@BananaCoding
@BananaCoding Год назад
Hi Lee, thanks for that video! Is there a way to use internationalization / i18n with the new app folder?
@leerob
@leerob Год назад
Hey! You can see supported/planned/unplanned features here: beta.nextjs.org/docs/app-directory-roadmap
@tamilshoutcom
@tamilshoutcom Год назад
If this is for nextjs 13, why set this inside _app.tsx file? Shouldn't it be under layout.jsx at the top level inside the app folder? It is not working if I do that btw, resorts to using default font thus asking. Thanks.
@amandakoster
@amandakoster Год назад
I am using nextjs 13 and this video does not offer a complete tutorial. My fonts loaded but all of my globals broke.
@ajamesdev
@ajamesdev Год назад
What is the best way to inject multiple fonts? Should I concatenate the fonts with the classNames library, or inject them as individual jsx global styles?
@joseandkris
@joseandkris Год назад
Have you found a way to do this?
@mridulranjan1069
@mridulranjan1069 7 месяцев назад
Hello, what color theme/scheme are you using in your code editor?
@isseihyoudou5522
@isseihyoudou5522 11 месяцев назад
if not specify a subset it will use all of them? or there's a default? and same question for the weights
@MrMazvaz
@MrMazvaz 8 месяцев назад
How do you go about creating your own fonts using localFont? Say I was creating a designsystem and wanted to support NextJS by creating my own font using localFont and the exporting that as an npm-package the rest of my company could install and use just like the Inter function you get from `next/font/google`. E.g: `import { CompanyFont } from "@company/font"`. Is this possible?
@ongptnjp
@ongptnjp Год назад
Thanks, but Can I import font from other source except google and local some such as some CDN site ?
@devrsion
@devrsion 11 месяцев назад
Is there a way to inject css vairable to html body? Because all popups, like dialogs, callouts need to be rendered on the body, which is beyond the pages custom app's control
@user-gm3lg8gp3m
@user-gm3lg8gp3m 8 месяцев назад
thank you so much for this
@shubitoxX
@shubitoxX Год назад
Nice, is SvelteKit support possible/planned?
@ICOReviewtoken
@ICOReviewtoken 10 месяцев назад
Hi bro. I have a custom font that I want to import locally but it doesn't accept it. Also if I want to give users the ability to choose their own fonts when using, for example users will set the font for different title tags and font base, can I do it in nextjs 13? Please give me solution. Thank you
@alik64
@alik64 10 месяцев назад
this is exactly that i was looking for !! thank you a lot !
@yewyewxd
@yewyewxd Год назад
NextJs team is a beast
@NathanBudd
@NathanBudd Год назад
Is there a way to install just `next/font/local`? I am planning on just using my woff2 file and don't need to install all of the Google fonts.
@chiubaca
@chiubaca Год назад
Amazing... If you're using local font file does next still know how to pair it with a suitable fallback?
@leerob
@leerob Год назад
Yes!
@chiubaca
@chiubaca Год назад
@@leerob magic!!
@alifranco2528
@alifranco2528 Год назад
my english is not the best but i could understand your explanation, really thanks
@OlleBergkvist
@OlleBergkvist Год назад
Would be amazing with a video on how to do background images with Tailwind and the new Next/Image component🙏
@dvkerns
@dvkerns Год назад
^ THIS 🙏🙏🙏
@Kingdutch01-Eng
@Kingdutch01-Eng Год назад
🎉🎉🎉
@amandakoster
@amandakoster Год назад
Yes please! Has anyone had luck with this? My fonts loaded but all of my global styles broke!
@Mugenremix
@Mugenremix Год назад
@@amandakoster I tried it a few times and its still very buggy although they claim its stable. Just download the font into your project and use it from there is proving the best way till now.
@thakurakash321
@thakurakash321 Год назад
I just noticed one thing with this after applying next font changes : on local I do not see any css request going for fetching fonts but on production, a request is made with this path "/_next/static/css/694ccb28f5d8ec18.css" which fetches my woff2 fonts. Anyone has idea on why on prod this happens?
@sidehustler6729
@sidehustler6729 11 месяцев назад
Hi, I want to use @next/font but In my case font family name will come from api side or external data. How can I do that with new font lib. I try dynamic loading font package. But it doesn't work. Please help!
@javadkh9400
@javadkh9400 Год назад
I want to use alternative font format in localFont in my next js app. I mean like what we do in @font-face in css that if browser doesn't support first one goes to next one. There is no example for this case In next js document and I don't know how can I do it.Can you help me?
@amandakoster
@amandakoster Год назад
Thanks for the video! I am using nextjs 13 (+ tailwind + react + typescript) and though my fonts loaded but all of my globals broke. there
@usamatahir6413
@usamatahir6413 Год назад
Thanks for the video
@georgeranch31
@georgeranch31 Год назад
Don't know if it's gonna work but Ill try it on my next js 12 project. Can upgrade yet. AWS amplify does support 13 yet
@me-yf2tv
@me-yf2tv Год назад
What a framework; this makes things so simple. Thank you!
@srdjanrakic3739
@srdjanrakic3739 7 месяцев назад
and if this would actually work, it would be perfect xD
@iamprincemuel
@iamprincemuel Год назад
Hi, awesome tutorial. Please what's the name of this vscode editor theme? Thanks
@antares-the-one
@antares-the-one 8 месяцев назад
does anyone know why all the fonts from the next 13 look fuzzy? Particularly the top part of the character. when I use Google's one by it looks perfect though...
@viktormoskalev2269
@viktormoskalev2269 Год назад
How can i set up second font for title by CSS module ? font-family:"inter" doesnot work
@balanceandbuild
@balanceandbuild 10 месяцев назад
How would you go about a scenario where you're using multiple local fonts? How to pass and use multiple fonts in the child components as required?
@leerob
@leerob 10 месяцев назад
nextjs.org/docs/app/building-your-application/optimizing/fonts#local-fonts
@endaogorman1
@endaogorman1 Год назад
i still see a network request for the inter fonts better to download them locally?
@user-xr4oo2xp7q
@user-xr4oo2xp7q 11 месяцев назад
What if the font is hosted in some other CDN? Anyway to import them without downloading it?
@juniorbytes
@juniorbytes Год назад
I'm use two fonts. We do need pass in file app and a tag main? This is a little strange.
@buddy.abc123
@buddy.abc123 Год назад
This is awesome
@user-wd8fk2iq8l
@user-wd8fk2iq8l Год назад
I was meesing my head around why my font was serif. Then I saw this quick additions of "font-sans" after the curly brackets :P
@SolomonManalili
@SolomonManalili 11 месяцев назад
If I have multiple local font (different weights), do I need to declare each .woff2 file per weight?
@leerob
@leerob 11 месяцев назад
nextjs.org/docs/app/building-your-application/optimizing/fonts#:~:text=If%20you%20want,be%20an%20array%3A
@serhatakti5740
@serhatakti5740 Год назад
Is there a way to add it globally without adding an additional element in _app.js?
@vitozdev
@vitozdev Год назад
Nice video bro, I wonder if this good practices helps with Headers original paths to configure in advanced next.config.js. Thank's
@mutesacedric4350
@mutesacedric4350 Год назад
Thanks alot!
@elgeneee
@elgeneee 4 месяца назад
May i know where u got ur hoodie from? Looks sick 🔥
@veliea5160
@veliea5160 Год назад
creating tailwind variable is not working. I try to use font in any child component with out setting globally, it does not work
@prakashk8984
@prakashk8984 3 месяца назад
I'm facing issue Failed to fetch `Roboto` from Google Fonts.
@snwdn
@snwdn Год назад
How can we get it to work in plain CSS or SCSS/SASS?
@akinjidesleek
@akinjidesleek Год назад
👍thanks Lee!
@haveagoodday544
@haveagoodday544 Год назад
Hi Lee, Great content, thanks. I use mui (previously material-ui) and with that this does not seem to work. It looked very promising, and I hope I am not applying it correctly. If you (or anyone reading) knows how to combine this with mui, it would be great to get some links to content. Mui references working with ThemeProvider, but then I think I am back to square one with getting my google font differently. Thanks,
@nadavbueno
@nadavbueno Год назад
Bumped into the same issue. What I did is set the typography.fontFamily prop in the MUI theme to 'unset' (note that you'll need to create a base theme with this settings and then create your theme using the base theme). However it feels like a hack and if there's a proper way to do it I'd be happy to know.
@Spectraevil
@Spectraevil Год назад
@@nadavbueno Thanks man!
@Renanrr87
@Renanrr87 Год назад
anyway to fix inside another ?i'd like to not create a waste tag
@Kap1tany
@Kap1tany Год назад
Can you load multiple fonts with @next/font?
@jrbprice
@jrbprice Год назад
I would like to know this too
@ordruker9675
@ordruker9675 Год назад
Same question
@Christomshack
@Christomshack Год назад
Also curious
@maciejwojda2774
@maciejwojda2774 Год назад
yes, I am also curious about adding more than one font family
@akhamr_
@akhamr_ Год назад
The answer is yes
@ioabhishek
@ioabhishek Год назад
Hi how i can call the particular variant in any tag if i have added multiple variants inside the src like below const proxima = localFont ({ src: [ { path: '../fonts/ProximaNova-Regular.woff2', weight: '400', style: 'normal', }, { path: '../fonts/ProximaNova-Medium.woff2', weight: '500', style: 'normal', }, { path: '../fonts/ProximaNova-Semibold.woff2', weight: '400', style: 'normal', }, { path: '../fonts/ProximaNova-Bold.woff2', weight: '400', style: 'normal', }, ] })
@ioabhishek
@ioabhishek Год назад
export default function App({ Component, pageProps }) { return ( ) } suppose i ahve to call it inside main then how i can do this for multiple src's
@GavinMcQuienn
@GavinMcQuienn 3 месяца назад
How do we assign specific fonts to specific elements, say.. font-1 assigned to h1, h3 && font-2 assigned to h2 && font-3 assigned to body? TIA
@GavinMcQuienn
@GavinMcQuienn 3 месяца назад
All good, I figured it out. Pass all required fonts to the , then in your css, apply these variable names to the required elements via the related css variable you specified, eg; h1 { font-family: var(--font-fontName1), sans-serif; } h2 { font-family: var(--font-fontName2), sans-serif; }, etc. - thanks again for this tutorial, it was uber helpful 👍
@WinchesterD
@WinchesterD 7 месяцев назад
Do the same but my roboto font doesn't apply, even though the className is applied.
@nishitsarvaiya1474
@nishitsarvaiya1474 Год назад
What font are you using in vscode? is it Fira code?
@leerob
@leerob Год назад
It's just the default!
@gabriellazcano256
@gabriellazcano256 Год назад
@next/font/local Font loader error: Cannot read properties of undefined (reading 'fs') Why is this????
@leerob
@leerob Год назад
This was fixed in 13.0.4!
@borsaniasushant1
@borsaniasushant1 Год назад
What about multiple local fonts with tailwind?
@Jack-ss4re
@Jack-ss4re 5 месяцев назад
cool! but isnt CDN faster than hosting the font files in our servers?
@notstevelam
@notstevelam 4 месяца назад
yah i dont get it. this just seems like a ridiculous, convoluted away to essentially host a google font locally, since this method apparently downloads the font into your project anyway?
@Jack-ss4re
@Jack-ss4re 4 месяца назад
@@notstevelam ill search for a way to import fonts from cdn and using Next fonts as fallback, seems to be the best approach
@olehyamhurov3753
@olehyamhurov3753 Год назад
How do I connect a second font?
@rohitdhende9969
@rohitdhende9969 Год назад
how can i add multiple font globally? adding multiple classnames? it is not working
@jazzymichael
@jazzymichael Год назад
It looks like it changed with the the new App directory structure that's replacing Pages
@wshacode7179
@wshacode7179 Год назад
what if I wanted to use 3 different fonts for my website ??
@zabialy2919
@zabialy2919 Год назад
What is this theme?
@_Faisal_Akbar
@_Faisal_Akbar Год назад
What if I have multiple local font with different font style and different weight ? My font css: @font-face { font-family: "droid-serif"; font-display: auto; font-style: normal; font-weight: 400; font-stretch: normal; src: url(/fonts/DroidSerif.woff2) format("woff2"); } @font-face { font-family: "droid-serif"; font-display: auto; font-style: normal; font-weight: 700; font-stretch: normal; src: url(/fonts/DroidSerif-Bold.woff2) format("woff2"); } @font-face { font-family: "droid-serif"; font-display: auto; font-style: italic; font-weight: 400; font-stretch: normal; src: url(/fonts/DroidSerif-Italic.woff2) format("woff2"); } @font-face { font-family: "droid-serif"; font-display: auto; font-style: italic; font-weight: 700; font-stretch: normal; src: url(/fonts/DroidSerif-BoldItalic.woff2) format("woff2"); }
@keeganburkett7252
@keeganburkett7252 Год назад
Same question here, currently trying to figure out how to handle two local fonts with different weights w/ Tailwind. Familiar with the old way (prior to Next 13) but it's unclear how to do this in Next 13
Далее
10 common mistakes with the Next.js App Router
20:37
Просмотров 176 тыс.
3 Ways to Add Custom Google Fonts in Next.js 14
14:44
$10,000 Every Day You Survive In The Wilderness
26:44
Все мы немного Адриана 😂😂😂
00:11
Dancing makes everything better 🕺🏼
00:16
Просмотров 3 млн
I DONT USE NEXT JS
54:01
Просмотров 314 тыс.
Learn CSS fonts in 7 minutes! 🔤
7:21
Просмотров 14 тыс.
Using Images in Next.js (next/image examples)
9:10
Просмотров 89 тыс.
How to Use Custom Fonts with Tailwind CSS
11:36
Просмотров 72 тыс.
How I'm Writing CSS in 2024
12:59
Просмотров 53 тыс.
Fetching Data Doesn't Get Better Than This
6:58
Просмотров 60 тыс.
Next js 15 is Here… New Changes Again?!
8:13
Просмотров 90 тыс.
Избранное печатает....
0:11
Просмотров 58 тыс.
Индуктивность и дроссель.
1:00