wonder95's avatar

Unable to use Google font in Vue/Inertia/Tailwind app

In my Vue3/Interia/Laravel/Tailwind v4 app, I need to make some modifications to match another site, and part of that is implementing the Hind Vadadora font. In order to make it more performant, my idea was to import the font and just run it locally, so I installed it via NPM

npm install @fontsource/hind/vadadora

added these lines to /resources/css/app.css

@config "../../tailwind.config.js";

@import '@fontsource/hind-vadodara/300.css';
@import '@fontsource/hind-vadodara/400.css';
@import '@fontsource/hind-vadodara/500.css';
@import '@fontsource/hind-vadodara/600.css';
@import '@fontsource/hind-vadodara/700.css';

and updated fontFamily in tailwind.config.js from this:

            fontFamily: {
                sans: ['Nunito', ...defaultTheme.fontFamily.sans],
            },

to this

            fontFamily: {
                sans: ['"Hind Vadodara"', 'Helvetica', 'Arial', 'Lucida', 'sans-serif'],
            },

I also had to remove this lines from app.blade.php

        <link rel="stylesheet" href="https://fonts.bunny.net/css2?family=Nunito:wght@400;600;700&display=swap">

Because that was overriding with the Nunito font. However, it seems that my config file wasn't even being read, because nothing changed. I added this to app.css

@config "../../tailwind.config.js";

@import '@fontsource/hind-vadodara/300.css';
@import '@fontsource/hind-vadodara/400.css';
@import '@fontsource/hind-vadodara/500.css';
@import '@fontsource/hind-vadodara/600.css';
@import '@fontsource/hind-vadodara/700.css';

and apparently that broke something, because I then lost my bg-indigo-*00 colors defined in the tailwind config

    theme: {
        colors: {
            transparent: 'transparent',
            current: 'currentColor',
            black: colors.black,
            white: colors.white,
            red: colors.red,
            orange: colors.orange,
            yellow: colors.yellow,
            green: colors.green,
            gray: colors.blueGray,
            indigo: {
                100: '#e6e8ff',
                300: '#b2b7ff',
                400: '#7886d7',
                500: '#6574cd',
                600: '#5661b3',
                800: '#2f365f',
                900: '#191e38',
            },
        },

So my question is, what do I need to do to get my installed Google font to work?

0 likes
3 replies
LaryAI's avatar
Level 58

You’re very close! Here’s a step-by-step explanation and corrections to get your Google font working with Tailwind in your Vue 3, Inertia, Laravel, and Tailwind v4 stack.

1. Install the Font You already did this:

npm install @fontsource/hind-vadodara

2. Import the Font in Your CSS Only import the font-source files, don’t use @config in your CSS file. The @config directive is for Tailwind v3+ and should generally be the very first statement in your CSS (if used at all), but it isn't needed unless your CSS is not located in the default place, or you have multiple configs. Most of the time, Tailwind automatically finds tailwind.config.js.

So, your /resources/css/app.css should look like:

@import '@fontsource/hind-vadodara/300.css';
@import '@fontsource/hind-vadodara/400.css';
@import '@fontsource/hind-vadodara/500.css';
@import '@fontsource/hind-vadodara/600.css';
@import '@fontsource/hind-vadodara/700.css';

@tailwind base;
@tailwind components;
@tailwind utilities;

Don’t add the @config directive unless absolutely required, and if so, it must come before any @import.

3. Update Tailwind Config

Your tailwind.config.js should include 'Hind Vadodara' in the fontFamily configuration. Note: it should use straight quotes, not HTML entities:

Note:
When you directly set theme.colors, you replace all the built-in colors unless you spread the defaults or use extend.colors. If you want to keep all default colors and override only indigo, do this:

const colors = require('tailwindcss/colors');
module.exports = {
  theme: {
    extend: {
      colors: {
        indigo: {
          100: '#e6e8ff',
          300: '#b2b7ff',
          400: '#7886d7',
          500: '#6574cd',
          600: '#5661b3',
          800: '#2f365f',
          900: '#191e38',
        }
      }
    },
    fontFamily: {
      sans: ['Hind Vadodara', ...defaultTheme.fontFamily.sans],
    }
  }
};

4. Rebuild Your CSS

After these changes, stop and restart your build/watch process to pick up on the config changes:

npm run dev
# or
npm run build

5. Double-Check Usage

If you want to force a specific element (like the body) to use your new font, add this in your app.css (optional, usually your tailwind config is sufficient):

body {
  font-family: 'Hind Vadodara', Helvetica, Arial, Lucida, sans-serif;
}

Or use Tailwind’s class:

<body class="font-sans">
  ...
</body>

Summary Checklist

  1. Remove @config from app.css (unless you really, really need it).
  2. Import fontsource files at the top of your app.css.
  3. Update fontFamily in your tailwind.config.js.
  4. Use extend.colors if only customizing some colors.
  5. Restart your build process.

Let me know if you need more troubleshooting steps! If you’re still not seeing the font, open DevTools > Computed Styles, inspect your font-family on a text element, and verify it’s applied.

wonder95's avatar

OK, so that's all pretty much what I have in place.

@import '@fontsource/hind-vadodara/300.css';
@import '@fontsource/hind-vadodara/400.css';
@import '@fontsource/hind-vadodara/500.css';
@import '@fontsource/hind-vadodara/600.css';
@import '@fontsource/hind-vadodara/700.css';

@import 'tailwindcss';
@plugin "@tailwindcss/typography";

Here is my entire tailwind.config.js

and FWIW, this is my <body> tag in app.blade.php:

    <body class="font-sans antialiased">
        @inertia
    </body>

But i'm still not getting my font to be used.

ian_h's avatar

Tailwind 4 moved away from the tailwind.config.js file (don't know if it still gets read, but the auto-updater will remove it). Everything is defined in the CSS file now.

In one of my recent projects, I defined this as:

typography.css contains:

It doesn't use external fonts, but maybe the rest of the setup is the same.

Please or to participate in this conversation.