Skip to content

How to use custom fonts with Tailwind CSS

FULL-STACK WEB DEVELOPMENT BOOTCAMP

2024 COHORT SIGNUPS END TOMORROW

Assuming you have an app configured to use Tailwind CSS, you’ll have a CSS file that contains

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

Go on Google Fonts for example, select a font, and you’ll be provided a @import for the CSS font.

For example this for the Inter font in various weights:

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;700;900&display=swap');

Add that to the CSS file, and then add this:

@layer base {
  html {
    font-family: Inter, system-ui, sans-serif;
  }
}

In the end, your CSS file will look like this:

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

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;700;900&display=swap');

@layer base {
  html {
    font-family: Inter, system-ui, sans-serif;
  }
}

Now your default font is that one, and you can use font-bold for example or font-medium to set various sizes.

→ Get my CSS Handbook
→ Read my CSS Tutorial
  • Learn modern web development in my BOOTCAMP (SIGNUP END TOMORROW FEB 20, 2024)
  • THE VALLEY OF CODE (+ PRO), your web development manual
  • I wrote 15+ coding BOOKS, all available in THE VALLEY OF CODE PRO
  • Indie solopreneur internet business masterclass SOLO LAB (summer 2024)