Skip to content

How to use custom fonts with Tailwind CSS

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.

→ Download my free CSS Handbook!

THE VALLEY OF CODE

THE WEB DEVELOPER's MANUAL

You might be interested in those things I do:

  • Learn to code in THE VALLEY OF CODE, your your web development manual
  • Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
  • I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
  • Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
  • Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
  • Find me on X

Related posts that talk about css: