How to Use Custom Fonts with Tailwind CSS

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

Комментарии • 107

  • @KingOfCorinth
    @KingOfCorinth 3 года назад +55

    For that one person who is under a time crunch
    Embedding Google Fonts: 0:37
    Self Hosted Fonts: 7:22

    • @N32-e1g
      @N32-e1g 2 года назад

      life saver bro

  • @hmatpin
    @hmatpin 3 года назад +1

    Man, thanks for not monetizing this great channel

  • @davidluhr
    @davidluhr 3 года назад +52

    Another great video, Simon! Bonus tip: use `font-display: swap;` in your `@font-face` declarations for a performance boost. This allows the browser to render first paint more quickly by displaying the system font as soon as possible, and then "swapping" to your custom fonts once they become available. It prevents the infamous FOUT (Flash of Unstyled Text) 😉

    • @simonswiss
      @simonswiss 3 года назад +2

      Totally, that would have been a great addition to this video 👍

    • @robyroby162
      @robyroby162 3 года назад +10

      Actually this brings FOUT back by design!

    • @davidluhr
      @davidluhr 3 года назад +6

      @@robyroby162 Sorry, I meant FOIT (Flash of Invisible Text). Thanks for correcting me!

  • @codenameunknown3791
    @codenameunknown3791 3 года назад +12

    8:13 looool. Big shoutout to Mr. Wes Bos out there.

    • @simonswiss
      @simonswiss 3 года назад +2

      Haha I was waiting for those comments 😅

  • @pedromartindelcampogonzale9613
    @pedromartindelcampogonzale9613 3 года назад

    Your vídeos are really uplifting, love your attitude.

  • @kayf7073
    @kayf7073 3 года назад +8

    Great. Remember, when your website is also seen by people living in europe, including files from external sources like google is against eu gdpr law, because it transfers personal data (ip adesss) to other parties (worst of all: in the us) without prior consent. So selfhosting fonts, scripts, images etc is the only way to go

    • @moracabanas
      @moracabanas 3 года назад

      I cannot believe this thing wth is going on laws...

  • @mohabedr5030
    @mohabedr5030 3 года назад +17

    Tailwind is the future

    • @Max-xp3tf
      @Max-xp3tf 3 года назад +4

      The future is Tailwind *

    • @81NARY
      @81NARY 3 года назад +3

      And the future is now!

    • @Max-xp3tf
      @Max-xp3tf 3 года назад +1

      @@81NARY 👀

    • @nitro4109
      @nitro4109 2 года назад +1

      And I'm from future

  • @oliverye55
    @oliverye55 2 года назад

    Amazing video! super direct and to the point!! love this.

  • @JimOHalloran
    @JimOHalloran 3 года назад +2

    Woohoo! Simon is winning at CSS and Year 4 Miniball! Division 1 no less!

  • @saschamajewsky7990
    @saschamajewsky7990 3 года назад +12

    When Tailwind CSS Merch?

  • @moracabanas
    @moracabanas 3 года назад +4

    If you import fonts with @import and extend your tailwind.config.js you must rebuild. HMR just won't apply that font until you Ctrl + c your Node terminal. It took me 3h to point that. At least using windicss

    • @melissawhite7522
      @melissawhite7522 2 года назад +1

      Learning Tailwindcss and just wanted to say thanks for the reminder. Was totally like "why ins't this working." and forgot the rebuild. :)

    • @shivankbatra5643
      @shivankbatra5643 Год назад

      thanks a lot man, 5hr for me to be precise and was about to give up before I saw this comment. Feeling really stupid but finally it works!

    • @yassminh
      @yassminh Год назад +1

      This comment should be pinned. You have saved me from wasting hours trying to figure out why it didn't work. Thank you!

  • @RobertWildling
    @RobertWildling Год назад

    Great and important video! - I Austria there is a weird law case going on, where a woman accuses more than 1000 website owners of not having been explicit enough about their Google Font implementation. She feels that here private data has been exposed. The case is not yet over, but it shows that it might be a good idea to self-host google fonts...

  • @justinoneill2837
    @justinoneill2837 3 года назад +1

    I'm trying to add a custom icon font library w/ this method (material design icons to be exact). it's acting a tad bit strange though. Would be cool to see another video on how Tailwind recommends doing this.

  • @christyjacob8551
    @christyjacob8551 3 года назад

    I just googled for this yesterday!!

  • @probelou
    @probelou 3 года назад +1

    If I have the one font with multiple weights and want to use the tw font-weight utility classes how do I declare that?
    E.g. class="font-fontName font-weight-normal" or class="font-fontName font-weight-bold".
    I tried this but the cascade wins so `fontName` uses 700 weight irrespective of the weight utility class.
    @font-face {
    font-family: "fontName";
    font-weight: 400;
    src: url("../public/fonts/font-name-400.woff2") format("woff2"), url("../public/fonts/font-name-400.woff") format("woff");
    }
    @font-face {
    font-family: "fontName";
    font-weight: 700;
    src: url("../public/fonts/font-name-700.woff2") format("woff2"), url("../public/fonts/font-name-700.woff") format("woff");
    }

  • @tomrowe2181
    @tomrowe2181 3 года назад

    Would have liked a V2.2 example of this in the video! I had to work it out myself the other day 😅
    Moving off CSS files was a game changer, but the docs are missing a lot of examples on how to customise certain things

    • @TailwindLabs
      @TailwindLabs  3 года назад +1

      This example was made in 2.2! The exact same technique has been working since v1 by the way, there is nothing different about adding custom fonts to Tailwind since version 2.2.

    • @tomrowe2181
      @tomrowe2181 3 года назад

      @@TailwindLabs Oh I meant without CSS files! 😅
      By defining font-faces in a custom plugin for the tailwind config

  • @DrHappybone
    @DrHappybone 3 года назад +1

    Can't get local fonts to load at all.. just flat out refusing to do it. Using Vite, npm run dev for the server and tried using public file in root. No matter what I do, it's not loading the fonts

  • @en3rr
    @en3rr Год назад

    Thanks this helps a lot!

  • @YazinS
    @YazinS 3 года назад

    Great video! I was hoping it would cover how to change the default body font? I don't see a class (e.g. font-body) that can be overridden?

  • @The_Penny_Seventeens
    @The_Penny_Seventeens 9 месяцев назад

    Thank you my website is one step closer!

  • @mike110111
    @mike110111 3 года назад +1

    Please can you do a video explaining css layout for beginners

  • @ICOReviewtoken
    @ICOReviewtoken Год назад

    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. I use nextjs 13, taiwincss. Thank you

  • @jobsphil9553
    @jobsphil9553 3 года назад +1

    I wish you provide html source together. I wonder how the regular / bold font applied to css.

    • @nbbhaskar3294
      @nbbhaskar3294 3 года назад

      Either font-bold tailwind class can be added to your html element. Or in @font-face declaration in your css file, you can specify font-weight: 700 and point src to the bold font file, that should it.

  • @edanbenatar
    @edanbenatar 2 года назад

    Would you have to define all the weight classes so that Tailwind behaves accordingly with the font weight utility classes?

  • @govindsaini8085
    @govindsaini8085 3 года назад

    Hi I m facing the pb of display I want to show in lg screen of image and mobile devices I want to show hidden of image "hidden md:block " I used but doesn't work show this kind of pb how to solve
    if possible as soon as reply for this question

  • @ovuokeaghwotu2389
    @ovuokeaghwotu2389 2 месяца назад

    How do make the imported custom font the global default font? Thank you.

  • @TheKumarAshwin
    @TheKumarAshwin 2 года назад

    how to avoid expected behaviour issue, as my custome fonts loads after the default font?

  • @BneiAnusim
    @BneiAnusim Год назад

    PRICELESS! Thanks 😉

  • @mattd5419
    @mattd5419 3 года назад +1

    how can we use variable fonts?

  • @lautaroriveiro
    @lautaroriveiro 2 года назад

    Thanks again!

  • @varun_y
    @varun_y 3 года назад

    when using with nextjs and self hosted fonts , i had to put link in head tag as well.

  • @codeative
    @codeative 3 года назад

    just awesome

  • @abdullahialhassan3700
    @abdullahialhassan3700 3 года назад

    I have a question, while you are using the jit kit fo you need a css folder too

  • @muskanbhatnagar7535
    @muskanbhatnagar7535 2 года назад

    Hi, is there a possibility to conditionally add a font? I have a multitenant setup, and for different client UI's, we support client specific fonts. In client A's app, I only use client A's font. But embedding fonts this way downloads client B's font as well even though it is not used.

  • @joshuarileymagic
    @joshuarileymagic 3 года назад

    I maybe thinking too advanced or might not be performant but since the JIT compiler CDN is JS and you can use [ ] in classes, wouldn't it be easier if the CDN auto-imported the google font if you use say font-[Roboto] then it'll auto import the font as a link tag in header and dynamically create the css needed, just an idea anyway :) I'm starting to look more into customising Tailwind after using the defaults for a while along with custom css

  • @cas4425
    @cas4425 3 года назад +2

    🔥🔥🔥

  • @CARUSAR21
    @CARUSAR21 3 года назад

    So epic once again.

  • @arianhossain9600
    @arianhossain9600 2 месяца назад

    what is the name of this font that in the VS Code????? if u know let me know

  • @hmatpin
    @hmatpin 3 года назад

    Hi. Does anybody know how to include the css of a third party library like slick slider into a tailwind project?

  • @momenabdelghafar7771
    @momenabdelghafar7771 3 года назад +2

    what is font-family in the text-editor

    • @HosamHasanMonir
      @HosamHasanMonir 3 года назад

      monolisa font

    • @anirudh1713
      @anirudh1713 3 года назад +2

      Its DankMono, its paid.

    • @modz9711
      @modz9711 3 года назад

      @@anirudh1713 yup it's dank mono..! Check the 'f' its unique ..!

    • @marcorieser
      @marcorieser 3 года назад +1

      I think it's MonoLisa, they released version 1.8 yesterday which adds a script variant that gives you a similar look like Dank Mono.

    • @modz9711
      @modz9711 3 года назад

      @@marcorieser will check it

  • @adeema664
    @adeema664 Год назад

    very good video 🥰🥰

  • @oliverye55
    @oliverye55 2 года назад

    Subscribed and liked!!

  • @nozimjonjuraev2666
    @nozimjonjuraev2666 Год назад

    can anyone tell me how to set up truetype font in project with tailwindcss?

  • @esdev
    @esdev 3 года назад

    Is it possible to use without tailwind config file , more preciously in new tailwind cli jit mode which doesn't require config file??

    • @simonswiss
      @simonswiss 3 года назад

      If you want a custom "font-${fontName}" utility class, you'll need a Tailwind config file. You can still use a custom font and set it in CSS on the HTML elements you want to target.

  • @ch3tankate469
    @ch3tankate469 3 года назад +1

    We want more such videos
    Plz reply this post if you want more

  • @Ravi0207
    @Ravi0207 Год назад

    Anyone struggling with using the next font optimisation with tailwind -
    In _app file declare the font as a jsx style css variable. And use that variable in the tailwind config file

  • @lawrencemotions8720
    @lawrencemotions8720 2 года назад

    How to add fonts in next js.

  • @irving7653
    @irving7653 Год назад

    What are the font and theme you use?

  • @OneBrokeBloke
    @OneBrokeBloke Год назад

    And local fonts, but as utility classes? Thats what im looking for

  • @aaymankhalid9997
    @aaymankhalid9997 Год назад

    I need to know the vscode theme being used in this video🙃

    • @simonswiss
      @simonswiss Год назад

      The theme is Night Owl, and the font is Dank Mono ✨

  • @phonghoanggia9181
    @phonghoanggia9181 3 года назад

    I just wanna know what font do u use in your text editor?

  • @bogdanlupu3679
    @bogdanlupu3679 3 года назад

    From what Tailwindcss version does this work? Does it work in 2.0 or 2.2 onwards?

    • @wobsoriano
      @wobsoriano 3 года назад +1

      Since v1

    • @simonswiss
      @simonswiss 3 года назад +1

      It was already working in v1, we just haven't provided many examples until now 👍

    • @bogdanlupu3679
      @bogdanlupu3679 3 года назад

      @@simonswiss thanks. I am new on tailwind and i plan to use in a project that nas custom fonts. The codebase vad installed 2.0. That's why the question. Thanks again for the answer.

  • @JamisIcon
    @JamisIcon 3 года назад

    Hi, thanks for the great tips, I'm kinda new to this, my font changed when I added it to the app.css file not the tailwind.config.js, I'm kind of wondering what happened :D

  • @Keteku.
    @Keteku. 2 года назад

    What font is he using in his code editor ? Any help here

    • @janascofield
      @janascofield 2 года назад +1

      operator mono

    • @Keteku.
      @Keteku. 2 года назад

      @@janascofield Will check it out. Huge thanks

  • @guilhermeeduardomaffei1247
    @guilhermeeduardomaffei1247 2 года назад

    which font do you use in Visual Code ?

  • @sherifsaleh111
    @sherifsaleh111 3 года назад

    What's the text editor font are you using 🙏?

  • @TheCrisisCall
    @TheCrisisCall 3 года назад

    Really very good video! I'll start implementing the fonts this way. On the other hand, does anyone know how to include style that should be in regardless of whether their classes are in the HTML or not? It happens that I apply style to a carousel but it only exists when the page loads, so the purged css does not contain the style

  • @waldothedev
    @waldothedev 3 года назад

    Haha, amazing...how do you say that again Wes? vit? veet? lol

  • @esdev
    @esdev 3 года назад

    Sweet 😎

  • @mychoppaeat
    @mychoppaeat Год назад

    1:00 eyo!

  • @parth.dobariya
    @parth.dobariya Год назад

    0:53 tujhe malum hai tu kya bolra hai😂

  • @mikefenn2451
    @mikefenn2451 Год назад

    8:15

  • @haridass2208
    @haridass2208 3 года назад

    Bye bye bootstrap 🤣

  • @vic_casanas
    @vic_casanas 3 года назад +1

    First

  • @shaungbhone8368
    @shaungbhone8368 3 года назад

    Beet