Skip to content
nkNilay Kabariya

Entry No.008·Fixes··1 min read

Fix: “Cannot apply unknown utility class” in Tailwind CSS v4

Two causes trigger this Tailwind v4 error: an unmapped theme variable (border-border) or a CSS file missing @reference. Both reproduced and fixed.

by Nilay#tailwind#css#shadcnFIXED

The error, verbatim

Jump to the fix ↓
Error: Cannot apply unknown utility class `border-border`

Error: Cannot apply unknown utility class `font-bold`. Are you using
CSS modules or similar and missing `@reference`?

Tested on

tailwindcss
4.3.3
CLI
@tailwindcss/cli 4.3.3
Node / npm
24.14.0 / 11.9.0
OS
Windows 11 Pro
Contents
  1. The fix01
  2. Why it happens02
  3. Why @reference and not @import03
  4. What didn’t work04

The fix

First look at which class the error names. That tells you which of two causes you have.

The class is a custom name like border-border, bg-background or text-foreground (common with shadcn/ui). Tailwind v4 only knows colours declared in @theme. Map your CSS variable into it:

@import "tailwindcss";

:root {
  --border: oklch(0.92 0 0);
}

@theme inline {
  --color-border: var(--border);
}

@layer base {
  * {
    @apply border-border;
  }
}

The class is a normal one like font-bold, and the file is a CSS module, a Vue or Svelte <style> block, or any CSS file that doesn’t import Tailwind. Add @reference at the top of that file:

@reference "tailwindcss";

.title {
  @apply font-bold text-xl;
}

If your main CSS defines its own theme, reference that file instead, for example @reference "../app.css";. That way your custom colours work inside the module too.

Why it happens

In v4, @apply can only use utilities that Tailwind knows about in that file.

  • Case 1: border-border isn’t a built-in class. It only exists once a --color-border theme variable is defined. Setups copied from Tailwind v3 defined these colours in tailwind.config.js, and v4 ignores that file unless you add @config.
  • Case 2: Tailwind processes each CSS module and component style block on its own. Those files never ran @import "tailwindcss", so even font-bold is unknown there. Tailwind v4’s own message now suggests @reference for exactly this case.

Why @reference and not @import

@import "tailwindcss" inside the module also makes the error go away, but it copies Tailwind’s base styles into every module that does it:

5,585 B

module with @import

base styles copied in

617 B

module with @reference

only .title

bigger output

@reference lets the file use Tailwind’s theme without outputting it.

What didn’t work

— N.K., end of entry No.008

Useful? Pass it on:Post on X

Related entries

  1. No.009

    Fix: “trying to use tailwindcss directly as a PostCSS plugin”

    Tailwind CSS v4 moved its PostCSS plugin to a separate package. The two-line change to postcss.config.js, reproduced and verified.

    > Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS

    FIXED1 min
  2. No.007

    Fix: npx tailwindcss init “could not determine executable to run”

    Tailwind CSS v4 removed the init command, so npx has nothing to run. Two fixes, both reproduced: set up v4 without a config file, or pin v3.

    > $ npx tailwindcss init

    FIXED2 min
  3. No.010

    Fix: Vite “Failed to resolve import” for @ alias imports

    Vite can't find an @/ import until the alias is in vite.config. Why tsconfig paths alone don't help, and the new Vite 8 Rolldown wording. Reproduced.

    > [vite] Internal server error: Failed to resolve import "@/utils/hello"

    FIXED1 min

Post card · Newsletter

Get the next fix in your inbox.

One short email when a new entry is published. No spam, never shared, and you can leave any time.

— Nilay

or follow by RSS

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text