Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

font-bold and font-light do nothing after setting a custom font family in Tailwind

Errorfont-light, font-normal and font-bold all look identical

Short answer

Tailwind only sets the CSS font-weight value. The browser can show that weight only if your font has a face for it. When the page loads a font with a single weight, every class renders the same. Check which weights the font actually loads, then request or declare the ones you use.

  • Applies to Tailwind CSS 4, Chrome, Google Fonts css2 API
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open DevTools, select the text, and look at the Computed tab. If font-weight shows the number you asked for, Tailwind is fine and the problem is the font files.

    getComputedStyle(document.querySelector('h1')).fontWeight
  2. 2Match what you see, then jump to its fix

    1. 1Computed font-weight changes, the glyphs do notThe font was loaded with one weight onlyFix
    2. 2Only the face you declared is ever usedA self-hosted @font-face declares no weight, or the wrong oneFix
    3. 3Weights between two available faces look the sameThe font has no face near the weight you requestedFix
    4. 4The custom font is not applied at allThe font import comes after other CSSFix

What does the error look like?

  • font-light, font-normal and font-bold all look identical
  • Computed font-weight is 700 in DevTools but the text looks regular

Cause 1 of 4

The font was loaded with one weight only

1Check

Google Fonts returns only the regular weight when the request has no weight axis. Look at the link or @import URL for a wght part.

grep -rn "fonts.googleapis.com" src/ app/ public/ 2>/dev/null

2Fix

Ask for every weight you use, or for a range when the font is variable.

@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap");
@import "tailwindcss";

3Verify

Reload and watch the Network tab: the font response must now be listed for each weight.

document.fonts.forEach(f => console.log(f.family, f.weight))

Confirmed by developers.google.com

Did this fix it?

Cause 2 of 4

A self-hosted @font-face declares no weight, or the wrong one

1Check

Each @font-face rule describes one file and its weight. Without a font-weight descriptor, the browser treats the face as a single default weight.

grep -rn "@font-face" -A6 src/ app/ 2>/dev/null

2Fix

Declare one rule per static file with its weight, or one rule with a range for a variable font file.

@font-face {
  font-family: "Oswald";
  font-style: normal;
  font-weight: 200 700;   /* variable file */
  src: url("/fonts/Oswald.woff2") format("woff2");
}

3Verify

Load the page and switch classes between font-light and font-bold.

document.fonts.forEach(f => console.log(f.family, f.weight))

Confirmed by tailwindcss.com

Did this fix it?

Cause 3 of 4

The font has no face near the weight you requested

1Check

When the exact weight is missing, the browser picks the nearest face by a fixed rule, and the computed value still shows the weight you asked for. A family with only 400 and 700 cannot show 600 differently from 700.

document.fonts.forEach(f => console.log(f.family, f.weight))

2Fix

Use a weight the font ships, or load a family or variable file that covers the weights your design needs.

/* use a weight that exists */
<h2 className="font-bold">Title</h2>

3Verify

Compare the rendered text at each class.

getComputedStyle(document.querySelector('h2')).fontWeight

Confirmed by developer.mozilla.org

Did this fix it?

Cause 4 of 4

The font import comes after other CSS

1Check

Browsers require @import rules before other rules. A URL import placed below @import tailwindcss is ignored.

head -n 5 src/index.css

2Fix

Put the font URL import first, then Tailwind, then the --font-* theme variable.

@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap");
@import "tailwindcss";

@theme {
  --font-roboto: "Roboto", sans-serif;
}

3Verify

The text now uses the family; check the Fonts pane in DevTools.

getComputedStyle(document.body).fontFamily

Confirmed by tailwindcss.com

Did this fix it?

How do I stop it coming back?

  • List every weight your design uses in the font request or @font-face rules.
  • Prefer a variable font file when you need many weights.
  • Check the DevTools Fonts pane after changing fonts, not only the class names.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Web apps

Tailwind is installed but the utility classes do nothing

Tailwind classes work in some components but not in others

When classes have no effect, the stylesheet either lacks the v4 import line, is never loaded by the page, or the class name never appears as plain text in a scanned file.

5 causes, each with a fix

Web apps

Hydration failed after adding next-themes dark mode

Console reports a server and client mismatch on the html element

next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.

3 causes, each with a fix

Web apps

Next.js fails with Cannot find module 'tailwindcss'

Error: Cannot find module 'tailwindcss'

Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.