ui: fontFamily is not applied in tailwind.config.js file

When I comment out the code below from tailwindcss.config.cjs file, I get sans-fonts displayed. Otherwise I get serif-fonts with the sans key somehow. How to get proper fonts?

fontFamily: {
    sans: ['var(--font-sans)', ...fontFamily.sans],
},

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 11
  • Comments: 15

Most upvoted comments

Just for anyone who does not like to read @pmabres solution (a) looks like this:

from

      fontFamily: {
        sans: ["var(--font-sans)", ...fontFamily.sans],
      },

to

      fontFamily: {
        sans: [...fontFamily.sans],
      },

Worked for me thanks!

So if you are following the manual install guide @lightbluepoppy you’ll find this issue as the css variable is not defined anywhere when doing a manual install ‘var(–font-sans)’ so resolving that fails and it falls back to a serif font. You can either define that css variable in the same css file you’ve defined the rest of the variables or you can just remove the variable usage and just use …fontFamily.sans

Docs should be updated, this got me too - https://ui.shadcn.com/docs/installation/manual

the following worked for me after adding the import statement in tailwind.config.js

import { fontFamily } from "tailwindcss/defaultTheme"

module.exports = {
..  
        theme:{
          ...
              extend: {
                    fontFamily: {
                      sans: ["var(--font-sans)", ...fontFamily.sans],
                      },
                }
          }
..
}

It looks like the manual documentation guide suggests an undefined fontFamily. Removing fontFamily altogether solves the issue.

Try removing “var(–font-sans)”, worked for me 😃

@shadcn : I followed the manual instruction and face the same issue. https://ui.shadcn.com/docs/installation/manual

for me issue was that in root layout i was passing font.className but need to be font.variable

Guys. have you been able to resolve the issue? I am getting same issue on my side.

@lightbluepoppy I’m not using the app router so I had to do some other things that solved my dropdown menu typography issue. I needed to update the _app.tsx and the _document.tsx.

In the _document.tsx I had to add this

<body className={`min-h-screen bg-background ${fontSans.variable} font-sans antialiased`}>

and in the _app.tsx I added a html wrapper and added the font-sans there as well

<main className={`${fontSans.variable} font-sans`}>

I thought it was weird it needed to be added in both places. Not sure how relevant that is for your use case but maybe that will trigger some ideas. Good luck!

@bluengreen This looks correct.

content: ['./src/**/*.{js,ts,jsx,tsx}'],